部署到IIS 7(而非Azure)中时,生产和暂存连接字符串应存储在ASP.NET Core应用程序中的什么位置?
我正在寻找推荐的方式/最佳做法,尤其是在安全方面。
在Visual Studio 2015中,您在项目属性中设置以下变量:ASPNET_ENV.如果将其设置为开发,则可以使用:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseErrorPage();
}
}
Run Code Online (Sandbox Code Playgroud)
IsDevelopment方法将检查ASPNET_ENV环境变量.现在,当您使用Visual Studio 2015时,这一切都很好.当您在生产服务器上将Web应用程序发布到IIS时,如何设置ASPNET_ENV的值?
我的服务器是Windows Server 2012
我有一个运行状况检查端点/status返回以下状态代码和响应正文:
200 OK?503 Service UnnavailableHTTP状态代码对于降级响应应该是什么?"降级"检查用于成功但速度缓慢或不稳定的检查.什么HTTP状态代码最有意义?
http health-monitoring http-status-codes http-status-code-503 kubernetes-health-check
我有以下实体框架实体:
public class Region
{
public int RegionId { get; set; } // Primary Key
public string Name { get; set; }
public virtual ICollection<Country> Countries { get; set; } // Link Table
}
public class Country
{
public int CountryId { get; set; } // Primary Key
public string Name { get; set; }
public int RegionId { get; set; } // Foreign Key
}
Run Code Online (Sandbox Code Playgroud)
我使用AutoMapper将这些映射到以下ViewModel:
public class RegionViewModel
{
public int RegionId { get; set; }
public string …Run Code Online (Sandbox Code Playgroud) 我有一个包含自定义错误页面的ASP.NET 5 MVC 6应用程序.如果我现在想在/api路径下添加API控制器,我使用Map方法看到了以下模式:
public class Startup
{
public void Configure(IApplicationBuilder application)
{
application.Map("/api", ConfigureApi);
application.UseStatusCodePagesWithReExecute("/error/{0}");
application.UseMvc();
}
private void ConfigureApi(IApplicationBuilder application)
{
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World from API!");
});
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在/api路径下创建了一个全新的独立应用程序.这很棒,因为您不希望Web API有自定义错误页面,但确实希望它们适用于您的MVC应用程序.
我是否正确地认为在ConfigureApi中,我应该再次添加MVC以便我可以使用控制器?另外,如何针对此子应用程序专门配置服务,选项和过滤器?有没有办法ConfigureServices(IServiceCollection services)为这个子应用程序?
private void ConfigureApi(IApplicationBuilder app)
{
application.UseMvc();
}
Run Code Online (Sandbox Code Playgroud) 使用 SwashBuckle 时的默认响应内容类型是text/plain。如何将默认值更改为application/json甚至删除text/plain?
我想使用NGINX 启用GZIP和Brotli压缩.我必须在我的nginx.conf中为每个提供自己的MIME类型列表,如下所示:
gzip_types text/plain
text/css
...etc;
brotli_types text/plain
text/css
...etc;
Run Code Online (Sandbox Code Playgroud)
如何创建可由两个设置使用的单个MIME类型列表?
我有几个OLTP数据库,API与他们交谈.我也有ETL工作每隔几个小时将数据推送到OLAP数据库.
我的任务是构建一个自定义仪表板,显示来自OLAP数据库的高级数据.我想构建几个指向OLAP数据库的API.我是不是该:
我试图动态加载包含ASP.NET Core Startup类的.NET Core DLL .然后我想实例化Startup该类并将其交给TestHostAPI,因此我可以在内存中启动该站点.我写了以下代码:
var directoryPath = @"C:\Dlls";
var assemblyFilePath = Path.Combine(directoryPath, "Foo.dll");
var assemblyName = AssemblyLoadContext.GetAssemblyName(assemblyFilePath);
var assembly = new AssemblyLoader(directoryPath).LoadFromAssemblyName(assemblyName);
var startupType = assembly.ExportedTypes
.FirstOrDefault(x => string.Equals(x.Name, "Startup"));
var webHostBuilder = new WebHostBuilder()
.UseStartup(startupType)
.UseUrls(new string[] { "http://localhost" });
using (var testServer = new TestServer(webHostBuilder))
{
var response = testServer.CreateClient().GetAsync("/");
}
public class AssemblyLoader : AssemblyLoadContext
{
private readonly string directoryPath;
public AssemblyLoader(string directoryPath) =>
this.directoryPath = directoryPath;
protected override Assembly …Run Code Online (Sandbox Code Playgroud) typeloadexception asp.net-core-mvc .net-core asp.net-core asp.net-core-testhost
在Azure Pipelines中,我启用了git标签来触发管道,如下所示:
trigger:
branches:
include:
- '*'
tags:
include:
- '*'
Run Code Online (Sandbox Code Playgroud)
现在,我想知道是否有一种方法可以通过编程确定:
asp.net-core ×4
.net ×1
.net-core ×1
api ×1
automapper ×1
azure-devops ×1
brotli ×1
c# ×1
cqrs ×1
git ×1
git-tag ×1
gzip ×1
http ×1
iis-7 ×1
nginx ×1
ngx-brotli ×1
olap ×1
oltp ×1
swashbuckle ×1