2016-09-22 9 views
0

example.comを入力すると、希望するとおりhttps://example.comにリダイレクトされます。 http://example.com/blogを入力するときしかし、それはまだどのように私はそれがユーザーが書いたものは何でも、HTTPSを追加することができますか? すべてのページのHTTPからHTTPSへのリダイレクト

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

https://example.comにリダイレクト

+0

ここでコードを試しましたか? http://stackoverflow.com/a/47095/993547 –

+0

はい。私はアウトバウンドルールを追加しましたが、まだルートにリダイレクトされています – crystyxn

+0

これを試してくださいhttp://stackoverflow.com/questions/32523540/http-to-https-rewrite-too-many-redirect-loops-iis-7詳細については、このArtical http://www.hanselman.com/blog/HowToEnableHTTPStrictTransportSecurityHSTSInIIS7.aspx –

答えて

1

コントローラーの属性[System.Web.Mvc.RequireHttps]を使用できます。

すべてのコントローラで必要な場合は、次のコードを使用できます(のみAsp.Net MVC6 /コア)。

public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddMvc(options => 
    { 
     options.Filters.Add(typeof(RequireHttpsInProductionAttribute)); 
    }); 
} 

注:そして、あなたはhttpリクエスト次回を使用するようにクライアントを避けるためにHSTSを使用することができます。

<system.webServer> 
    <httpProtocol> 
     <customHeaders> 
     <add name="Strict-Transport-Security" value="max-age=31536000"/> 
     </customHeaders> 
    </httpProtocol> 
</system.webServer> 
+0

のBlogControllerに従ってください。またはホーム? – crystyxn

+0

@crystyxnは、httpsを使用する必要があるすべてのコントローラで[RequireHttps]属性を使用します。 – qin

+0

imはASP.NET MVC 5 – crystyxn

関連する問題