I have a website running under IIS which has an SSL certificate applied. We would like to enforce HTTPS usage for the website which is easily done by checking the "Require Secure Channel" box, but this will immediately break the ability for people to connect over HTTP (as designed).
What I'd like to do is find a way to automatically redirect people from HTTP -> HTTPS if they type in the wrong thing (or connect from an old bookmark).
Is there a way to do this without creating a second website in IIS?
I posted this on StackOverflow
If the server/site/vdir is configured using the "Require Secure Channel" setting, the response from the server will be a "403.4 Forbidden: SSL is required to view this resource." error or a "403.5 Forbidden: SSL 128 is required to view this resource.".
You can actually customize the 403.4 or 403.5 error to redirect back to HTTPS. Create a VDIR under your site with NO SSL Requirement (**This is Important) - I use "CustomError". Create an ASP File inside this directory called 403_4_Error.asp containing the following:
Edit the server/site/vdir's Custom Error property for 403.4/403.5 and set the MessageType to URL and the URL to "/CustomError/403_4_Error.asp".
Note that ASP is used, you could easily use ASP.net or any other scripting language.
If you need to do it at the server level then you will have to create another site and have it forward the the https site.
If you can edit the code, you can not enforce ssl at the server level, instead you can do it in your website by detecting if the url starts with http: and redirecting to the same url with https: instead.
We ended up doing this in our application code; our page base class checks early on whether it's in HTTP, and redirects to HTTPS as required. It really depends on how much you trust your application code :)