Sunday, December 5, 2010

How to show/hide iframe in ssl/non-ssl pages in asp.net

Last week I was working on a task where we had to disable the facebook like box on a ssl pages because of security issues with the controls which are not coming from within our website. We are including the widget within our master page, that means that it will be part of all the child pages, doesn't matter if they are ssl or non-ssl. After some testing, here is how I resolved the problem, and have the widget enabled on non-ssl pages, and have the widget disabled on ssl pages.

Here is the iframe received from Facebook:


<iframe src="http://www.facebook.com/plugins/likebox.php?href=www.facebook.com%2Fwebsite&width=180&colorscheme=dark&connections=6&stream=true&header=false&height=605" style="border: medium none; overflow: hidden; width: 177px; height: 605px;" allowtransparency="true" frameborder="0" scrolling="no"></iframe>

Now what I am doing is I am checking the connection with:

                      <% if (Request.IsSecureConnection.Equals(false))


If the page is non-ssl display the iframe, and if the page is ssl don't display the iframe and disable ir from rendering.
Here is the complete source code:


<div>

                      <% if (Request.IsSecureConnection.Equals(false))

                           { %>

                           <br /><br />

            <iframe src="http://www.facebook.com/plugins/likebox.php?href=www.facebook.com%2FyourWebsite&width=180&colorscheme=dark&connections=6&stream=true&header=false&height=605" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:177px; height:605px;" allowTransparency="true"></iframe>                      

                       <br />

                         <a style="float:left;" href="http://twitter.com/YourWebsite" target="_blank" style="float: right"><img src="images/twitter_Web.jpg" title="Follow me on Twitter" width="162 height="69" /></a><br />

                    

                        <% } %>

                     </div>



Thanks for reading and comments always appreciated.

Follow me on twitter: http://www.twitter.com/AngelArnaudov

No comments:

Post a Comment