ASP.NET Core 技能测试题
-
在哪种情况下,选择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)
原文:https://www.cnblogs.com/gougou1981/p/12199658.html