Sign In  |  Register
 
 DotNetNuke Powered!
DotNetNuke Support Forums

Switch to SSL and back using Javascript

Rate this topic:

Please Register to post a reply.
Another benefit of registration is the ability to subscribe to and recieve notifications of new posts.

AuthorMessages
John Mitchell
Posts:3550



02/19/2007 6:36 PM  

UPDATE:

For those that are using this Javascript method, I have made the code easier to implement.  All you need to do is change the top variable to add more pages that you want to secure.

var secureUrlPattern='login|Cart|/590/';
 if(location.protocol.toLowerCase()=='http:'&&location.href.match(secureUrlPattern))
     location.href=location.href.replace('http:','https:');
 else if(location.protocol.toLowerCase()=='https:'&&!location.href.match(secureUrlPattern))
      location.href=location.href.replace('https:','http:');

--This is the first version, you do not need to read any further if you are using the easier version above.

< script type="text/javascript">
    if(location.protocol.toLowerCase() =='http:' && 
        location.href.toLowerCase().indexOf('login') > -1 
)  
             location.href = location.href.replace('http:','https:');

    if(location.protocol.toLowerCase() =='https:'
&& 
         location.href.toLowerCase().indexOf('login') == -1 )
             location.href = location.href.replace('https:','http:');
< /script >

The first IF statment in the code above is looking to see if your using http and on the login page then tells the browser to switch to the same location but use SSL.

The second IF statment does just the opposite, so any time you are on a page with the word "login" in the url it will tell the browser to use SSL, if you are not on a url with "login", then it will switch back.

Just change the word "login" with "cart" or whatever might be in the Url if you want to do it with different pages.  That is all you need, paste this at the top of your page, (or skin in DotNetNuke), or include it in an external Javascript file that is linked in.

 

patrick1010
Posts:42



04/17/2007 11:23 AM  
Hi John,

Thanks a lot for this tip and for such a lot of useful informations about DotNetNuke!
Patrick
John Mitchell
Posts:3550



04/17/2007 2:14 PM  
Thanks for the "feedback fuel" Patrick ;)
cstatham
Posts:2



07/04/2007 11:19 AM  
John, you are a master of many things DNN.

You have helped me tremendousely with my site menu and I thank you for that.

I am trying to use wwwStore and have installed a cert in IIS, but cannot browse the site using SSL.

Any feedback?
cstatham
Posts:2



07/04/2007 11:39 AM  
When I login I get an error with https?
John Mitchell
Posts:3550



07/04/2007 1:39 PM  

First you'll need to make sure that SSL is working on your site.

One way to do this is to eliminate other possible problems by just making a simple request using SSL.

Try this using your own domain name:

https://www.snapsis.com/spacer.gif

If you are able to request that image with SSL and there are no errors then you have SSL working correctly.  If not then you will need to get the certificate applied correctly in IIS.

What error are you getting when trying to login using SSL?  Is it a JS Error?  Any error messages?

peterg
Posts:3



09/11/2007 12:17 PM  

Where should I place this script? Can you tell me?

Thank you.

John Mitchell
Posts:3550



09/11/2007 3:33 PM  
You just need to get it into the page output. I put it at the top of my skin file.
peterg
Posts:3



09/11/2007 4:55 PM  

Which skin file did you put it, in particular. Also how do I call different pages. For example if I want to call "my account" page to be under the SSL. What if I want to secure more than one page, how I can do that?

Thanks.

John Mitchell
Posts:3550



11/10/2007 5:33 PM  

 

Sorry Peter, I missed this question earlier.

This example extends the same process to allow for more pages. You basically just need to Check for login OR cart to turn it on, and check that it is not login AND not cart to turn it off.

<script language="Javascript1.1" type="text/javascript">
    if(location.protocol.toLowerCase() =='http:' &&
       ( location.href.toLowerCase().indexOf('login') > -1 || 
         
location.href.toLowerCase().indexOf('cart') > -1  ))  
             location.href = location.href.replace('http:','https:');

    if(location.protocol.toLowerCase() =='https:'
&& 
         location.href.toLowerCase().indexOf('login') == -1 && 
         location.href.toLowerCase().indexOf('cart') == -1)
             location.href = location.href.replace('https:','http:');
</script>

 

peterg
Posts:3



11/10/2007 6:32 PM  
Can you tell me where to put this code?
John Mitchell
Posts:3550



11/11/2007 7:54 AM  

If you look at the page source for your page and search for Skin.css you can find the folder that your skin is in.
In that folder will be a skinname.ascx file. You can put this code in there.

If you have different skins applied to different pages then you may need to add it to those other skins as well.

thecidd
Posts:3



05/16/2008 12:45 PM  

Hi John - Page source?  You mean the address of the page, correct?  I'm sorry I don't know how to read this path.  Can you elaborate once more?

John Mitchell
Posts:3550



05/16/2008 12:59 PM  
If you use View > Page Source from the main menu of FireFox you can look at the HTML code of the page.

You can also put this in the Default.aspx page, but you will need to remember that if you ever upgrade since that page gets updated on each version of DNN.
Please Register to post a reply.
Another benefit of registration is the ability to subscribe to and recieve notifications of new posts.

Forums >DotNetNuke Support >Tips-And-Tricks > Switch to SSL and back using Javascript



ActiveForums 3.7
Visit our Store for great DotNetNuke Modules and Skins
DotNetNuke CSS Menu 3.3.4 (single use)

Item codeCSSNM33SU
AuthorJohn Mitchell
Base Price$25.00
Product Information 
DotNetNuke CSS NavMenu 3.3.4 (Developers)

Item codeCSSNM33DEV
Base Price$149.00
Product Information 
Snapsis PageBlaster 3.3.2 Performance for DotNetNuke - Professional Edition

AuthorJohn Mitchell
Base Price$25.00
Product Information 
XDAkuna (Web 2.0 CSS XHTML Skin)

AuthorNina Meiers
Price$49.00
Product Information 
XDAmarina (CSS & Flash Skin)

AuthorNina Meiers
Price$49.00
Product Information