views:

294

answers:

2

I have an asp.net appliction on the one server. There I've added code on server-side in Page_Load:

Response.AddHeader("key", "password-key-from-hotel");

On the client side I have a form:

<form ... action="www.link-to-another-domaint" >
    <input type="hidden" id="asd" value="fgh" > 
    .... 
</form>
<script type="text/javascript">
    document.forms[0].submit(); 
</script>

Then on the other domain - there is also my other application - I'm trying to get the hedaer "key" by this code:

Request.Headers["key"].ToString();


But there is no such header. Is there is a desicion? Where is my mistake?

A: 

as i understood you need request field, not header. try:

Request["asd"]
Andrey
No, I need to get the header "key" with the value "password-key-from-hotel".
Sirius Lampochkin
@Sirius Lampochkin - how do you plan to request browser to send extra header? i don't think it is possible.
Andrey
A: 

You're adding http header from the server-side and then trying to post form from the client-side.

So, you lose your header.

AFAIK, you cannot add http header from the client-side with form submit (as an exeption could be XHR and other plugins; but it seems, your post is cross-domain, so ajax won't work).

I don't understand the whole reason of doing it, but the easiest way to pass custom header from one page to another is to use Server.Transfer method.

Source page:

Response.AppendHeader("key", "password-key-from-hotel");
Server.Transfer("www.link-to-another-domain");

Destination page (even another domain):

string key = Request.Headers["key"];

This should work. But Server.Transfer method has its own limitations.

Alex
So... Is there a way to send a custom http-header from one domain to anoother?
Sirius Lampochkin
@Sirius Lampochkin: yep, server-side form, server-side post and then redirect/transfer to the target page.
Alex
@Sirius Lampochkin: pass it using hidden input
Andrey