1

I am using the code HttpContext.Current.Request.UrlReferer ?? (Object)).ToString() in my project to get the referrer URL from my hosted application.

When I am redirecting from an HTTP page then I am able to get the URL, but if I'm redirecting from an HTTPS page then I am getting a null value, how can I get UrlReferrer working for HTTPS?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Kapil Gadhire
  • 11
  • 1
  • 2
  • @ChaitanyaGadkari don't use `inline code` to highlight random terms. – CodeCaster Jul 06 '15 at 11:59
  • The referrer doesn't get sent, as explained in [Is HTTP header Referer sent when going to a http page from a https page?](http://stackoverflow.com/questions/1361705/is-http-header-referer-sent-when-going-to-a-http-page-from-a-https-page). You shouldn't build your application logic on the referrer anyway, because certain browsers, users or plugins can disable referrers altogether. Explain the problem you are trying to solve by using the referrer; perhaps there's a better solution for it. – CodeCaster Jul 06 '15 at 12:03

1 Answers1

2

That behavior is by design. URLReferrer header should not be sent for SSL requests. See:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3

"Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP request if the referring page was transferred with a secure protocol."

So, in your case HttpContext.Current.Request.UrlReferrer would be null and If information about the urlreferrer isn't sent, there really isn't much you can do, may be you could just use HttpContext.Current.Request.Url.Host

StackTrace
  • 9,190
  • 36
  • 114
  • 202