2016-09-22 2 views
0

example.com을 입력하면 원하는대로 https://example.com으로 리디렉션됩니다. http://example.com/blog를 입력 할 때 그러나 여전히 https://example.com모든 페이지에 대해 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를 추가 할 수 있습니다로 리디렉션?

+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 자세한 내용은 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

메신저 ASP.NET MVC를 사용하여 5 – crystyxn

관련 문제