2017-09-22 43 views
0

我们有一个Asp.Net核心Web应用程序,它运行在.Net框架(net452)上,并作为Web App托管在Azure中。Azure Web App - 将所有流量从http重定向到https

我试图将所有http请求重定向到https。

我目前的理解是:

  1. 我不能在web.config中指定IIS重写规则的应用 是一个Asp.Net核心应用
  2. 我不能使用微软 。 AspNetCore.Rewrite中间件版本2.0.0.0它 需要.Net Standard 2.0,并且net452仅支持.Net标准 1.5。

如果以上内容是正确的,那么做到这一点的最好方法是什么?

我目前正在考虑写一个小中间件的,但感觉就像必须有一个更简单的方法...

回答

1

,我真的怀疑为点1 ,因为它是一个IIS设置。 <system.webServer>下的任何内容只与IIS相关,而不是与您使用的技术相关,即使使用PHP/Java/pureHtml应用程序,您仍然可以使用该部分添加重写规则。重写将在您的请求到达您的应用程序之前发生。但对于天蓝色的应用程序,你的意思是需要启用ARR,它曾经有一些问题与重写规则,但现在应该没问题,因为最近我只是在一个新的Azure应用程序中为PHP应用程序设置了一些规则

+0

我们使用的是IIS改写这是工作在web.config规则。 – TonE

0

This将所有http流量重定向到https。它还确保网站热身请求获得通过,这使网站交换和Always On场景中的工作正常。

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document- 
Transform"> 
<location path="%XDT_SITENAME%" xdt:Transform="InsertIfMissing" 
xdt:Locator="Match(path)"> 
<system.webServer xdt:Transform="InsertIfMissing"> 
    <applicationInitialization xdt:Transform="InsertIfMissing"> 
    <add initializationPage="/" xdt:Transform="InsertIfMissing"/> 
    </applicationInitialization> 

    <rewrite xdt:Transform="InsertIfMissing"> 
    <rules xdt:Transform="InsertIfMissing"> 
     <rule name="Force HTTPS" enabled="true" stopProcessing="true"> 
     <match url="(.*)" ignoreCase="false" /> 
     <conditions> 
      <add input="{HTTPS}" pattern="off" /> 
      <add input="{WARMUP_REQUEST}" pattern="1" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" 
appendQueryString="true" redirectType="Permanent" /> 
     </rule> 
    </rules> 
    </rewrite>  
</system.webServer> 

相关问题