Summit
Summit

Reputation: 1243

Set Referer header in asp.net

  This should be an easy question, but I've been unable to solve it. I'm trying to change the Referral header prior to redirecting the page of an HttpResponse object. I know this can be done in an HttpWebResponse, but can't get this to work for a standard Page.Response.
  I'm trying to just set the referer header to look like it originated from a temp page on my site (this is for analytics tracking for an external system).
 Is this possible to do??
 I've tried to use the code below (as well as variations such as Response.AppendHeader and Response.AddHeader), however the Referer always shows as the page that the Request initiated from.

      Response.Headers.Add("Referer", "http://test.local/fromA");
      Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri);

If not via .net can this be accomplished via js?
Thanks!

Upvotes: 5

Views: 14039

Answers (2)

Mark Brackett
Mark Brackett

Reputation: 85655

Referer is controlled (and sent) by the client. You can't affect it server-side. There may be some JavaScript that you could emit that'd get the client to do it - but it's probably considered a security flaw, so I wouldn't count on it.

Upvotes: 6

Martin Liversage
Martin Liversage

Reputation: 106826

The referrer is set by the client, not the server. It is useful to include in a request and not a response as it points to the URL where the request came from.

Upvotes: 5

Related Questions