seth
seth

Reputation: 1389

Redirect from HTTP to HTTPS - IIS 7.5

I have implemented https on my application and now i'm trying to make IIS redirect all http request to https, so that the user doesn't even notice this change.

I have changed and tried some of the IIS options but with no luck.

How can i do this?

I'm using IIS 7.5 and ASP.NET 2.0

Regards,

Upvotes: 10

Views: 11770

Answers (5)

ferreidon aftahi
ferreidon aftahi

Reputation: 47

Redirect from HTTP to HTTPS in IIS 7

URL Rewrite is tightly integrated with IIS Manager for better management(Download from https://go.microsoft.com/?linkid=9722532)

enter image description here

Configure Rule Settings

Match URL tab:
name= Redirect 2 HTTPS
url= (.*)

Conditions tab: add record
input= {HTTPS}
pattern= ^OFF$

Action tab:
type= Redirect
redirection URL= https://{HTTP_HOST}/{R:1}
redirectType= Permanent

Upvotes: 0

Fergus
Fergus

Reputation: 2982

Just in case someone else runs into a http:// site that will not redirect. You also have to have the port 80 binding added to the site.

enter image description here

Upvotes: 1

Aristos
Aristos

Reputation: 66641

you can make a simple check on the global.asax, on beginRequest, something like this code:

protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication)sender;

        if(!app.Response.Request.IsSecureConnection)
        {
            app.Response.Redirect(Request.RawUrl.Replace("http://","https://"), true);
            return;
        }
    }

ps. I did not have check this code, I just type it now.

Upvotes: 3

a_major_de
a_major_de

Reputation: 171

The approach described in this blog article works well.

Summary:
1) Turn on "Require SSL" setting for the site.
SSL Settings

2) In the Error settings configuration for 403 errors set it to "respond with 302 redirect" with the new URL set to the full URL with the https:// prefix.
Change Error Page
Set Redirect Properties

Upvotes: 17

DanielB
DanielB

Reputation: 20210

You can install the RewriteModule and follow the instructions on this page.

Upvotes: 10

Related Questions