views:

106

answers:

2

Hi,

I want to redirect http to https. I tried this one,but I have one problem, I have to redirect to another page. The request.url gives the current page, whereas I need to redirect to another page. How do I do that.

if(!Request.IsSecureConnection)

{
  string redirectUrl = Request.Url.ToString().Replace("http:", "https:");

  Response.Redirect(redirectUrl);

}

Regards

cmrhema

+2  A: 

The code you posted will create the exact same URL, only with an https: perfix, as you are simply replacing http: with https::

string redirectUrl = Request.Url.ToString().Replace("http:", "https:");

If you want to redirect to another page, simply do that:

Response.Redirect("https://example.com/anotherPage.aspx");
Oded
A: 

I have used Switching Between HTTP and HTTPS Automatically: Version 2 with minor modifications very successfully. Takes a lot of the work out of it.

Sky Sanders