Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Our domain is in now http protocol. It will be going to change to https after some time. I wanted to do such a code if user type http://domainName then all relative link on that page would be redirected to http automatically. IF user type https://domainName then all relative link on that page would be redirected to https automatically.
How I can do that using asp.net.

What I have tried:

I am trying to do it through client side javascript or jquery but not able to figure out how..
Posted
Updated 4-Aug-16 5:48am
Comments
Richard Deeming 4-Aug-16 11:59am    
Why not just use relative links on the page?

<a runat="server" href="~/pageInRootOfApplication.aspx">
<a href="/pageInRootOfSite.aspx">
<a href="pageInSameFolder.aspx">
<a href="../pageInParentFolder.aspx">

Those will all be resolved relative to the current URL, including the protocol. If the page is loaded over HTTP, the links will also load over HTTP. If the page is loaded over HTTPS, the links will load over HTTPS.

The only time you have a problem is if you specify the full URL to your site:
<a href="http://www.yoursite.com/somePage.aspx">

I believe you are in the wrong direction. You don't need to change your code, neither JavaScript nor JQuery can help you in this regard. This is basically configuration stuffs.

You need to configure your IIS to handle https requests. If you want your website to use both http and https protocols then you'll need 2 ports.

Please refer following articles to learn step by step process.
What is SSL and How to Implement in ASP.Net Web Application[^]
Building Secure ASP.NET Applications: Authentication, Authorization, and Secure Communication[^]
Switching Between HTTP and HTTPS Automatically: Version 2[^]
https://support.microsoft.com/en-us/kb/299875[^]

Hope, it helps :)
 
Share this answer
 
What you need to do is redirect the initial http request rather than amending the links on the page, so if someone requests http://yoursite/url you redirect them to https://yoursite/url. That way all the links\images will be https by default (assuming you have written your site correctly).

Google "asp.net redirect http to https" and you'll find various ways of achieving this.
 
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