I'm trying to set the headers and redirecting to a different page like this –
Response.Headers.Add("id", "testtest");
Response.Redirect("http://www.somesite.com/somepage.aspx");
And in the page_load
of somepage.aspx, I'm checking the request for headers –
if (!string.IsNullOrEmpty(Request["id"]))
{
// do something with "id"
}
But Request["id"
] is always null. How do I get the values of the header in the new page? I do not want to use query strings.
Thanks!
Update:
Here's a little more detail — I have two ASP.NET v4 web applications (Site 1 and Site 2) running on two different machines. Site 1 has just one aspx form and it has only one button on it. On button click, I hit the database and get the value I need and should pass it on to Site 2. In the Global.asax of Site 2, I'll be reading the header information received from Site 1 and use the value.
Update #2:
I was able to get it to work —
Response.Write(
string.Format(
@"<form action='{0}' id='test' method='POST'><input type='hidden' name='key' value={1} /></form>
<script type='text/javascript'>
document.getElementById('test').submit();
</script> ",
"http://www.somesite.com", "1234"));
In the destination site, I was able to get the value using –
Request["key"]
Best Answer
HTTP headers are valid only for the current response. When you set a redirect the current response contains your custom header but when the browser follows the redirect location those headers are no longer present. Furthermore you are using
Request["id"]
in the other page so you need to sent the value as query string: