How to do a Server Side include with C# in ASP.NET

BlueKnight66
BlueKnight66 used Ask the Experts™
on
I want to include some java script on a page only when the page is not using SSL (HTTPS).  Example, I have "mypage.aspx" and "mypage.aspx.cs" . I only want the javascript to be used(displayed) on the "mypage.aspx" when it is being accessed vis "HTTP" and NOT "HTTPS".  How and where would I place the conditional code and the test for SSL.

Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Surround your javascript code in a Panel in your aspx page, we'll use ID Panel1, then in your code behind in Page_Load you can see if it's ssl and show/hide the panel, example code below.
protected void Page_Load(object sender, EventArgs e)
{
  if(Request.ServerVariables["HTTPS"] != "on")
  {
     Panel1.Visible = true;
  }
}

Open in new window

Author

Commented:
That was exactly what I was looking for and it worked great.  I'm applying for use with Google AdSense ads.  This way the warning boxes and ads won't appear when using SSL.  Thanks again!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial