Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have SSL certificate and congigured on one of my website. I want to navigate my website always on https always, for eg.
if i use www.mywebsite.com then should use https automatically
if i use http://www.mywebsite.com then should use https automatically
if i use mywebsite.com then should use https automatically

My website is hosted on Windows Server 2003 and using IIS 6.0
Posted
Updated 2-Jun-15 21:56pm
v2
Comments
F-ES Sitecore 28-May-15 4:08am    
google "asp.net redirect to https". Depending on if it is webforms or mvc depends how you implement this but you need to detect if the request is http and then issue a redirect to the same page but on https.
Richard Deeming 3-Jun-15 4:43am    
You should be looking to upgrade or replace your server ASAP. You have slightly over a month until Windows Server 2003 support ends completely:
https://www.microsoft.com/en-gb/server-cloud/products/windows-server-2003/[^]
After July 14, Microsoft will no longer issue security updates for any version of Windows Server 2003.
ZurdoDev 3-Jun-15 7:42am    
You can turn on a setting in IIS that says "Require SSL" or something like that.
Mayank_1986 4-Jun-15 2:35am    
I have not seen any option available on IIS 6.0 to redirect on HTTPS.
ZurdoDev 4-Jun-15 7:38am    
No, not redirect. Require ssl. It means if someone types in http only they will get a message in their browser that the site requires ssl. So, they'll have to type in https.

1 solution

I have achieve this by adding a simple code on Global.asax

C#
protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
        {
            Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]);
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900