小编Nat*_*lai的帖子

ASP.NET Core 2.1 App Engine中没有HTTP / HTTPS重定向

问题

当应用发布到App Engine时,我无法从HTTP自动重定向到HTTPS才能正常工作。

当我通过example.com访问该网站时,该站点被路由到http://www.example.com,并显示该连接不安全。当我通过https://www.example.com访问该网站时,该网站便由Google管理的SSL正确保护。但是,不会发生从HTTP到HTTPS的自动重定向。

不安全的连接

我还在Log Viewer中收到一个错误,警告Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware抛出该错误,无法确定重定向的https端口。

在此处输入图片说明

我遵循了MSDN上的文档,仅使它在本地运行,但未在将应用发布到App Engine时使用。 https://docs.microsoft.com/zh-cn/aspnet/core/security/enforcing-ssl?view=aspnetcore-2.1&tabs=visual-studio

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseDatabaseErrorPage();
    }
    else
    {
        app.UseStatusCodePages();
        app.UseExceptionHandler("/Error");
        app.UseHsts(); // This was added by the template
    }

    app.UseHttpsRedirection(); // This was added by the template
    app.UseStaticFiles();
    app.UseCookiePolicy();
    app.UseAuthentication();
    app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)

这是Program.cs。基本上从项目模板默认

public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
    return WebHost.CreateDefaultBuilder(args)
        .CaptureStartupErrors(true)
        .UseStartup<Startup>();
}
Run Code Online (Sandbox Code Playgroud)

用于部署的app.yaml

runtime: aspnetcore
env: flexible
automatic_scaling:
  min_num_instances: 1
  max_num_instances: 20
  cpu_utilization:
    target_utilization: …
Run Code Online (Sandbox Code Playgroud)

c# asp.net google-app-engine google-cloud-platform asp.net-core

10
推荐指数
1
解决办法
2370
查看次数

DbContext.Find() 和 DbContext.SingleOrDefault() Entity Framework Core 的区别

使用Find()和从上下文查询数据时有什么不同Single()。两者都返回被请求的实体。

我在 Microsoft 上发现的一些示例正在使用Single,SingleOrDefault变体来查询实体。一些使用Find方法。

使用其中之一时是否有任何“性能”优势?

c# entity-framework entity-framework-core

0
推荐指数
1
解决办法
1016
查看次数