2012-09-13 77 views

回答

7

您可以通过IIS Rewrite module做到这一点:

http://www.iis.net/downloads/microsoft/url-rewrite

http://www.iis-aid.com/articles/how_to_guides/redirect_http_to_https_iis_7

<rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
     <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
    </conditions> 
    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> 
</rule> 

或者你也可以通过Global.asax文件重定向:

protected void Application_BeginRequest(Object sender, EventArgs e) 
{ 
    if (!Request.IsSecureConnection) 
    { 
      string path = string.Format("https{0}", Request.Url.AbsoluteUri.Substring(4)); 

      Response.Redirect(path); 
    } 
} 

http://forums.asp.net/t/1340392.aspx

+0

非常感谢。使用IIRF文件怎么样? (我只是为了以防万一);) – born2fr4g

相关问题