首页 > Web开发 > 详细

ASP.NET Core 技能测试题

时间:2020-01-16 10:52:07      阅读:344      评论:0      收藏:0      [点我收藏+]

 

 

  • 在哪种情况下,选择WCF比选择ASP.NET核心Web API更有利?

技术分享图片

  • TagHelper中使用TagHelperOutput提供的SuppressOutput方法,禁止内容输出

TagHelper学习相关连接:https://www.cnblogs.com/shenba/p/6697024.html

技术分享图片

 

 

 

 

这里使用TagHelperOutput提供的SuppressOutput方法。

新建如下TagHelper

技术分享图片
[HtmlTargetElement(Attributes = "show-for-action")]
    public class SelectiveTagHelper : TagHelper
    {
        public string ShowForAction { get; set; }
        [ViewContext]
        [HtmlAttributeNotBound]
        public ViewContext ViewContext { get; set; }
        public override void Process(TagHelperContext context,
        TagHelperOutput output)
        {
            if (!ViewContext.RouteData.Values["action"].ToString()
            .Equals(ShowForAction, StringComparison.OrdinalIgnoreCase))
            {
                output.SuppressOutput();
            }
        }
    }
技术分享图片

这个TagHelper定义了其标签内容只有在当前Action跟目标Action一致的时候在显示内容,否则调用Suppress禁止内容输出

比如如下html标记

<div show-for-action="Index" class="panel-body bg-danger">
<h2>Important Message</h2>
</div>

指定了只有在Index action下才显示important Message

 

  • 使用依赖注入的好处是什么?对象的集中生命周期管理

技术分享图片

  • 如何使用 使用await调用异步方法?

技术分享图片

 

  • 使用DbContext的DbSet属性注册domain class

技术分享图片

如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data.Entity;
using TemplateTest1.Models;

namespace TemplateTest1
{
    public class EFContext : DbContext
    {
        public EFContext()
            : base("Default")
        {
            
        }
        
        public DbSet<AdGroupAdPositions> AdGroupAdPositions { get; set; }
        public DbSet<CompanyAddresses> CompanyAddresses { get; set; }
        public DbSet<AdPositions> AdPositions { get; set; }
        public DbSet<CompanyContacts> CompanyContacts { get; set; }
        //还有很多属性
    }
}

  

  • 在生产环境中运行时,使用什么决定应用程序正在使用的环境设置?

 

在以前的 ASP.NET 版本中,我们将应用程序配置设置(例如数据库连接字符串)存储在web.config文件中。 在 Asp.Net Core 中, 应用程序配置设置可以来自以下不同的配置源。

    • 文件(appsettings.json, appsettings..json) Environment环境不同,托管在对应环境。
    • User secrets (用户机密)
    • Environment variables (环境变量)
    • Command-line arguments (命令行参数)

 

相关连接:https://www.seoxiehui.cn/article-148803-1.html

 技术分享图片

 技术分享图片

 

  •  ASP.NET核心MVC web应用程序中使用Areas的主要好处?

 

区域提供了一种将大型web应用程序划分为易于管理的较小功能单元的方法

 

 技术分享图片

 

 

  •  将Microsoft.Extensions.SecretManager.Tools NuGet包添加到.NET core项目后,调用哪个.NET core命令行以显示为应用程序配置的user secrets?

假设说最后一项,每个开发要使用自己本机的数据库,你可能会说让每个人修改自己的web.config,在提交代码的时候不提交就行了。那么如果在web.config添加其他配置项的时候,显然不提交web.config文件不合理的。

现在,ASP.NET Core 提供了一种很优雅简洁的方式 User Secrets 用来帮助我们解决这个事情

  (相关连接:https://www.cnblogs.com/savorboard/p/dotnetcore-user-secrets.html

 

 技术分享图片

 

 

 

 

ASP.NET Core 技能测试题

原文:https://www.cnblogs.com/gougou1981/p/12199658.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!