Checking whether page is secure or not in ASP.NET or JavaScript

Recently in one the project we require to check whether page is secure or not as we are going to open a new popup window from that page and that why we need to pass https protocol if we have that page secure. I have search lots of things on internet and I have found following ways of finding whether page is secure or not in ASP.NET or JavaScript.

In ASP.NET There are two way of doing it. Either we can use current request to check whether it is secured or not or we can use server variables to check whether it it secure or not just like following.

HttpContext.Current.Request.IsSecureConnection

Here in above code If this returns true then Page is secured otherwise it is not Or you can use following server variable to check the protocol.

Request.ServerVariables["SERVER_PROTOCOL"]; 

In JavaScript you can document.location.protocol to check whether page is secure or not. Just like following.

document.location.protocol=='https:'

So you can see its very easy to check whether page is secure or not. Hope you liked it… Stay tuned for more..

Shout it
Published Thursday, April 07, 2011 1:23 AM by Jalpesh P. Vadgama

Comments

# re: Checking whether page is secure or not in ASP.NET or JavaScript

Friday, April 08, 2011 4:16 AM by chandu123

Where i have to use it?

# ?????? ???????????????? ???? ????????????????? ??????????????????????, ???????????? ???6 | ???????????????? ????????: ????????

Pingback from  ?????? ???????????????? ???? ????????????????? ??????????????????????, ???????????? ???6 | ???????????????? ????????: ????????

# Что почитать на выходных? Рекомендуем, выпуск №6

Friday, April 08, 2011 5:31 AM by Блог Владимира Юнева

Это подборка статей на тему веб-разработки на платформе .NET (и не только). За день перед выходными я

# re: Checking whether page is secure or not in ASP.NET or JavaScript

Friday, April 08, 2011 3:21 PM by Jalpesh P. Vadgama

Chandu123- You can use when you are opening a popup from page which is secure.

# re: Checking whether page is secure or not in ASP.NET or JavaScript

Monday, April 11, 2011 1:30 AM by chandradev1

Hi

It is very useful tips. Thanks for sharing.

Leave a Comment

(required) 
(required) 
(optional)
(required)