views:

89

answers:

3

In the web app (C#, ASP.NET) I am working on at the moment, the value in Request.Headers["Referer"] can determine things like custom style. I have created a custom page with a drop down menu to test this functionality. So when the selected index changes, the value selected should be set in the Request.Headers["Referer"] then will be redirected (Response.Redirect), the receiving page will then pick up the value in Request.Headers["Referer"] and adjust the styling accordingly. However I haven't been able to set value for Request.Headers["Referer"]. Is it possible at all?

Website 1 sets the value in Request.Headers["Referer"], e.g. www.xyz.com and before doing Response.Redirect to www.website2.com

Website 2 picks up value in Request.Headers["Referer"], in this case www.xyz.com and do what it needs to do, i.e. styling etc.

+1  A: 

use query string to easily perform the same task.

HotTester
website 2 is beyond my control (it's possible to get 'them' to update their code but it will take ages) and that's why i am going through the trouble try to mimic request header referer.
Jeffrey C
+2  A: 

You can't do this. The Request.Headers["Referer"] value is a value sent by the browser on each request. It's up to the browser what value it choose to supply for this value, and there is no means for a web page to send a response that says "for your next request, use this value for the Referer". And when you do a Request.Redirect, you're sending a response to the browser, telling it to make another request.

So whatever you're trying to achieve, this attempted method is not going to be the way to do it.

Damien_The_Unbeliever
+1. Have written the similar answer. Understanding how web and http actually works is rebirth of a web-developer. Modern frameworks hide these details. I'm really proud I started as classic-asp-developer.
this. __curious_geek
+1  A: 

You can simply not do this the way you're trying to do.

Why ??

The Request.Headers in this case, are the request headers received from the web-client - in most cases a browser. If you need to modify or add headers of an Http Request you first need to act as an HttpClient, just like the browser does. Once the request reaches the Http-server, in your case your website 1, you can not modify its values because its not allowed to do so. Because of this reason you cannot modify the request headers and then redirect to website 2 with modified headers. you'll have to give up either of the thing.

As others have mentioned you can redirect to website 2 with values in query-string.

this. __curious_geek