【问题标题】:Request.IsHttps and Request.Scheme are showing that request is HTTP instead of HTTPSRequest.IsHttps 和 Request.Scheme 显示请求是 HTTP 而不是 HTTPS
【发布时间】:2018-06-10 13:19:15
【问题描述】:

我正在使用 .Net Core Web 应用程序,我需要验证请求是 HTTPS。我已经在 Azure 中使用 Let's encrypt 安装了一个证书,并且我有一个 cloudflare CDN,但总是向我显示请求不是 HTTPS。

我用过

this.Request.Scheme.Equals("https")

this.Request.IsHttps

你知道发生了什么吗?

【问题讨论】:

    标签: c# .net asp.net-core .net-core


    【解决方案1】:

    Cloudflare CDN 虽然以 HTTPS 的形式为您的请求提供服务,但实际上是以 HTTP 的形式向您的网站发出请求。

    您可能正在使用 Cloudflare 的 Flexible mode。您可能想要使用其中一种Full 模式。

    【讨论】:

      【解决方案2】:

      这通常发生在您的 CDN (Cloudflare) 通过 HTTP 向您的 Web 服务器发送请求时。

      您可以指示 Cloudflare 仅使用 HTTPS,或通过 ASP.NET 在本地强制执行此操作。

      如果 Kestrel 直接暴露在互联网上,那么您实际上可以指示 Kestrel 将请求从 HTTP 重定向到 HTTPS。

      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
              app.UseDatabaseErrorPage();
          }
          else
          {
              app.UseExceptionHandler("/Home/Error");
              app.UseHsts();            // <=== Add this =====
          }
      
          app.UseHttpsRedirection();    // <=== Add this =====
      }
      

      【讨论】:

        猜你喜欢
        • 2019-01-14
        • 1970-01-01
        • 2012-12-17
        • 2011-05-03
        • 1970-01-01
        • 2019-08-16
        • 2017-06-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多