【问题标题】:Redirect to HTTPS except localhost重定向到 HTTPS,除了 localhost
【发布时间】:2019-06-14 22:49:53
【问题描述】:

我在 IIS 中托管了 asp.net core 2.2.1 应用程序。

我如何强制执行 HTTPS,除非请求来自/到 localhost。

【问题讨论】:

  • 您只想在生产环境中强制实施 HTTPS?或者请求何时来自本地主机?
  • 不,在生产中,当我登录服务器时,我想在没有 https 的本地主机上测试页面

标签: iis asp.net-core asp.net-core-2.2


【解决方案1】:

对于UseHttpsRedirection 的条件,您可以尝试MapWhen,如下所示:

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-06-29
  • 1970-01-01
  • 2016-12-09
  • 2020-12-28
  • 1970-01-01
  • 2014-12-13
  • 2019-09-15
  • 1970-01-01
相关资源
最近更新 更多