Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET site. Redirect whole domain from http to https

Just like in a title. How to redirect whole domain for example: http://testdomain.com.au/ to https://testdomain.com.au/ Can i do it in IIRF file ? If yes how this should look like ? How to bind IIRF file to site ?

like image 403
born2fr4g Avatar asked Dec 26 '22 17:12

born2fr4g


1 Answers

You can do this via an 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>

Or you can redirect via the Global.asax file:

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

like image 170
Darren Avatar answered Jan 13 '23 10:01

Darren