Link to home
Start Free TrialLog in
Avatar of JCM0165
JCM0165

asked on

vb.net redirect http <--> https without absolute url

There are 1-3 pages in my app I need secure. How can I have the pages automatically go to https for those pages only without using an absolute url in the redirect?

Thanks in advance.
Avatar of OriNetworks
OriNetworks

I work with C# so here is the code for C#. If you know C# and VB.NET you should be able to easily convert this.

All its doing is looking at the request variable

//if not secure connection
if(!Request.IsSecureConnection) 
 
{ 
  //then replace http: in the URL with https:
  string redirectUrl = Request.Url.ToString().Replace("http:", "https:"); 
 
 //now go to the new secure URL
  Response.Redirect(redirectUrl); 
 
} 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of OriNetworks
OriNetworks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JCM0165

ASKER

Great, that works on going to that page, so it's half the battle.
 
The other half is, what can I do with the reponse.redirects to relative links going from the secure page to other pages? In this case I want to switch from https back to http.
 
thanks
any pages goin back to http, you can either add a reverse type of code on all of the other pages or hard code each of the links on the https page to say http://mysite.com/regularpage.aspx