Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What is the best way to force HTTP requests to HTTPS requests on IIS 6? For example, I have both a directory and a whole site that I need to force HTTPS on for two different servers. What is the best or preferred method of accomplishing this? This will need to redirect requests that come in on HTTP to HTTPS. I was thinking of something along the lines of mod_rewrite from the Linux world.

Note that I already have a certificate installed and working.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Sometimes I have a hard time deciphering exactly what's being asked, but I think this is what you're after:

Right click the web site in question in IIS Manager, click the Directory Security tab, click the Edit button under the Secure communications section, check (enable) the Require secure channel (SSL) check box.

share|improve this answer
    
Will that redirect people coming in from HTTP to HTTPS? –  John Nov 10 '11 at 0:44
    
No, it's not a redirect, it's configuring the site so that only SSL connections will be accepted. I kind of thought I was misunderstanding what you were asking. –  joeqwerty Nov 10 '11 at 0:46
    
That's okay, do you know how to force a redirect? –  John Nov 10 '11 at 0:47
    
I don't, sorry. Someone else will chime in soon enough though. –  joeqwerty Nov 10 '11 at 0:48
1  
Here's a Google search returning several methods for achieving this: google.com/… –  joeqwerty Nov 10 '11 at 0:50

One method is to include this in your global.asax.cs.

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (!Request.IsSecureConnection)
    {
        Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl);
    }
}

See:

http://stackoverflow.com/questions/47089/best-way-in-asp-net-to-force-https-for-an-entire-site/47095#47095

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.