Click here to Skip to main content
16,018,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All

suppose i have two sites are https://test.com and http://test.com.

Earlier, my files were on http://test.com (non-secure) now i have migrated them on https://test.com (secure). So now there are no files on http://test.com (non-secure).

now i want to set a page(say default.aspx) on http://test.com (non-secure) that redirect me to https://test.com (secure site)?

how can i do this?

thanks,
krunal

What I have tried:

.............................................
Posted
Updated 29-Jan-23 4:41am
v3

Hi,

You can even redirect your site using DNS entry from your server. That way you do not have to keep default page on your old site. just made one entry to redirect page on the new https location.

If you want to redirect using your default page then you can use Response.Redirect to change page to https.

Hope it works for you,
Thanks.
 
Share this answer
 
Comments
kk2014 12-Oct-12 4:47am    
hi amit,
thanks for the quick reply. let i know you update...
AmitGajjar 12-Oct-12 4:49am    
Your welcome.
kk2014 12-Oct-12 5:51am    
hi amit,

is it possible that without i hardcode in my application, if i write http://test.com or test.com in adress bar, then it directly redirect to https://test.com.
i don't want to write code in http://test.com.
which setting i do in https://test.com redirect me to https://?
AmitGajjar 12-Oct-12 5:55am    
You can get the domain name in the page and then build the URL by appending https in URL and redirect on that location.
kk2014 12-Oct-12 7:29am    
hi amit,

i have putted physical page and redirecting to https://.
it works for me.

thanks,
krunal
There are several methods to do this. Check this link:

http://www.sslshopper.com/iis7-redirect-http-to-https.html[^]

I think that the simplest one is setting up a custom error page. Try and let us know!

Cheers
 
Share this answer
 
Try following code in global.asax

//This code work only on server
C#
void Application_BeginRequest(object sender, EventArgs e) 
    {
        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http:"))
        {
            Response.Redirect(HttpContext.Current.Request.Url.ToString().ToLower().Replace("http:", "https:"));
        }
    }


Thanks
 
Share this answer
 
Comments
[no name] 12-Oct-12 5:06am    
my 5

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