If you want to redirect HTTP to HTTPS, it is highly recommended that you use the URL Rewrite feature. You can download this feature FREE of charge from
http://www.iis.net/download/urlrewrite
If you are looking for a host that supports URL Rewrite, you can take a look at
asphostcentral.com
Please mark this response as an "answer" if it helps you. Thanks heaps!
294de3557d9d...
Member
16 Points
3 Posts
Redirect HTTP to HTTPS
Jan 19, 2012 02:38 PM|LINK
Using Microsoft ASP.NET with ASP.NET MVC on IIS 7.5.
We want our website to always use HTTPS.
But we cant entirely close HTTP (port 80) because some people will type the URL without https:// and then their web browsers will assume http://.
So I would like to make people who visit on http:// to get redirected to https://, how can I do this?
</div>bbcompent1
All-Star
32982 Points
8508 Posts
Moderator
Re: Redirect HTTP to HTTPS
Jan 19, 2012 02:45 PM|LINK
I've used this project before as a reference: http://www.codeproject.com/KB/web-security/WebPageSecurity_v2.aspx
Bruce L
All-Star
18102 Points
2841 Posts
Re: Redirect HTTP to HTTPS
Jan 19, 2012 09:25 PM|LINK
The best way to do this is to use URLRewrite module. Add a rule similar to the followings
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
http://www.discountASP.NET
necro_mancer
Star
8017 Points
1574 Posts
Re: Redirect HTTP to HTTPS
Jan 20, 2012 05:13 AM|LINK
hi completely agree with Bruce,
If you want to redirect HTTP to HTTPS, it is highly recommended that you use the URL Rewrite feature. You can download this feature FREE of charge from http://www.iis.net/download/urlrewrite
If you are looking for a host that supports URL Rewrite, you can take a look at asphostcentral.com
Please mark this response as an "answer" if it helps you. Thanks heaps!
Professional SQL 2008 R2 Service
bbcompent1
All-Star
32982 Points
8508 Posts
Moderator
Re: Redirect HTTP to HTTPS
Jan 20, 2012 11:22 AM|LINK
Agreed, the URL Rewrite would be your best option. Good one Bruce!
294de3557d9d...
Member
16 Points
3 Posts
Re: Redirect HTTP to HTTPS
Jan 23, 2012 09:34 AM|LINK
Thanks for you help, it worked.
I used the URLRewrite module. Had to change some permissions to get it to install though.
294de3557d9d...
Member
16 Points
3 Posts
Re: Redirect HTTP to HTTPS
Feb 21, 2012 02:30 PM|LINK
I found another way that works too. Edit the Global.asax file and add the following:
protected void Application_BeginRequest() { if (Request.Url.Scheme == "http") { var path = "https://" + Request.Url.Host + Request.Url.PathAndQuery; Response.Status = "301 Moved Permanently"; Response.AddHeader("Location", path); break; } }I use this to add HTTP Strict Transport Security support:
// HTTP Strict Transport Security protected void Application_BeginRequest() { switch (Request.Url.Scheme) { case "https": Response.AddHeader("Strict-Transport-Security", "max-age=300"); break; case "http": var path = "https://" + Request.Url.Host + Request.Url.PathAndQuery; Response.Status = "301 Moved Permanently"; Response.AddHeader("Location", path); break; } }necro_mancer
Star
8017 Points
1574 Posts
Re: Redirect HTTP to HTTPS
Feb 22, 2012 01:16 AM|LINK
thanks for sharing...
two thumbs up for you :)
Professional SQL 2008 R2 Service