I don’t know if this is really what you want, but in general you can fool the value of the UrlReferer property (even if it is read-only) in HttpContext.Current.Request using a little reflection.
For example:
FieldInfo fi = HttpContext.Current.Request.GetType().GetField("_referrer", BindingFlags.NonPublic | BindingFlags.Instance); string initialReferer = HttpContext.Current.Request.UrlReferrer.ToString(); if (fi != null) fi.SetValue(HttpContext.Current.Request, new Uri("http://example.com")); string fakedReferer = HttpContext.Current.Request.UrlReferrer.ToString();
In VS; These are the values before and after changing the UrlReferrer:
initialReferer "http://localhost/Test/Default.aspx" fakedReferer "http://example.com/"
If you open the System.Web assembly using ILSpy , you will notice that the UrlReferrer property looks something like this:
public Uri UrlReferrer { get { if (this._referrer == null && this._wr != null) { string knownRequestHeader = this._wr.GetKnownRequestHeader(36); if (!string.IsNullOrEmpty(knownRequestHeader)) { try { if (knownRequestHeader.IndexOf("://", StringComparison.Ordinal) >= 0) { this._referrer = new Uri(knownRequestHeader); } else { this._referrer = new Uri(this.Url, knownRequestHeader); } } catch (HttpException) { this._referrer = null; } } } return this._referrer; } }
Icarus
source share