-1

I have asp.net application hosted on server, Is there any way to find out whether users come from HTTPS or HTTP,I have tried URL referrer but seems its not working for request coming from HTTPS to HTTP.

Please suggest some way out?

Tester Manual
  • 59
  • 1
  • 6
  • Correct me if I'm wrong but I believe you can not trust HTTP headers since the client may specify what it wants to. – Kolyunya Aug 13 '13 at 06:56

3 Answers3

0

Do you need this for the purpose of forcing HTTPS? You may want to check out this answer - ASP.NET: best practice for redirecting to https

I'm using the URL Rewrite answer with great success.

Community
  • 1
  • 1
Paul McLean
  • 3,450
  • 6
  • 26
  • 36
0

The Referrer header is a bit unreliable and not clearly specified. However, most clients will not populate the header if the origin page was served over https. That does not mean that you can assume that an empty header means it came from https, since there are other reasons why they might not have filled it, but it is an indicator.

troelskn
  • 115,121
  • 27
  • 131
  • 155
0

Have you tried Request.UrlReferrer

Uri MyUrl = Request.UrlReferrer;
 Response.Write("Referrer URL Port: " + Server.HtmlEncode(MyUrl.Port.ToString()) + "<br>");
 Response.Write("Referrer URL Protocol: " + Server.HtmlEncode(MyUrl.Scheme) + "<br>");

Reference http://msdn.microsoft.com/en-us/library/system.web.httprequest.urlreferrer.aspx

Also take a look at this..

http://www.codeproject.com/Questions/104895/Is-there-any-alternative-for-UrlReferrer-and-HTTP_

and this http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.referer.aspx

Learning
  • 19,469
  • 39
  • 180
  • 373