【问题标题】:How to disable HTTP URL direction in .NET Core Kestrel如何在 .NET Core Kestrel 中禁用 HTTP URL 方向
【发布时间】:2021-02-11 04:39:53
【问题描述】:

应用程序 URL 适用于 HTTP 和 HTTPS。我想禁用 HTTP 并只维护 HTTPS。

禁用 (HTTP://10.25.65:7001) 和 启用 (HTTPS://10.25.65:7001)

【问题讨论】:

    标签: c# ssl .net-core


    【解决方案1】:

    是我第一次阅读“禁用”网址。我们通常在 Web.config 上进行从 http 到 https 的重定向。在 .Net Core 中,您还可以激活 UseHttpsRedirection,因为我在此处复制/粘贴以方便您完成任务:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
      }
      else
      {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
      }
    
      app.UseHttpsRedirection();
      app.UseStaticFiles();
    
      app.UseRouting();
    
      app.UseAuthorization();
    
      app.UseEndpoints(endpoints =>
      {
          endpoints.MapRazorPages();
      });
    }
    

    https://docs.microsoft.com/es-es/aspnet/core/security/enforcing-ssl?view=aspnetcore-5.0&tabs=visual-studio#usehttpsredirection

    【讨论】:

    • 是的。我也这样做了。但它没有重定向。当我使用 HTTP 时,结果为空。HTTP 到 HTTPS 重定向不起作用。
    • 您对端口感到困惑。你不应该通知端口,或者至少,你应该为 https 使用不同的端口。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    • 2020-06-15
    • 2021-08-19
    相关资源
    最近更新 更多