代码之家  ›  专栏  ›  技术社区  ›  Liero

重定向到https,localhost除外

  •  0
  • Liero  · 技术社区  · 6 年前

    我在IIS中托管了ASP.NET Core 2.2.1应用程序。

    如何强制HTTPS,除非请求来自/到本地主机。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Edward    6 年前

    条件 UseHttpsRedirection 你可以试试 MapWhen 如下所示:

    app.MapWhen(context =>
    {
        var url = context.Request.Path.Value;
        return url.Contains("localhost") && !context.Request.IsHttps;
    }, subapp =>
    {
        subapp.UseHttpsRedirection();
    });
    
    推荐文章