Add the headers to httpwebrequest/httpwebresponse from .net code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

how to add the headers to httpwebrequest/httpwebresponse from .net code ?
 
Vivek said:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?

Use WebRequest.Create as normal, cast it to HttpWebRequest, and use the
Headers property.
 
Jon Skeet said:
Use WebRequest.Create as normal, cast it to HttpWebRequest, and use the
Headers property.
thanks Jon
can you send me the code?
 
Ok, let me re-phrase the question here, this is what needs done:

We need to create an asp.net application, which validates a user and on
success transfers/redirects the user to another asp.net application after
adding a custom header to the request stream eg. ValidatedUserName.

When we add header to current request object and then redirect using
server.transfer() we don't get this header on the target aspx page (yes, we
tried after setting the preserve headers to true), what we think the cause
can be is that when server.transfer is called it creates a new request to the
target server and the headers that we added in the current request are not
available in that request.

We also tried adding headers in request and then getting the response after
creating a WebResponse object via WebRequest.Create(<url>) (this time it was
just a test to see if the headers were actually added when the request was
created, not redirecting as actually needed) and viola we got the header in
the target application (but this didn't helped much as what we need is a
redirect with header).

Please advice how can we do a redirect to a different webapplication by
adding custom header in request stream (there has to be a overwrite
somewhere, so that we can do what we need here).

Thanks!
 
Vivek said:
Ok, let me re-phrase the question here, this is what needs done:

We need to create an asp.net application, which validates a user and on
success transfers/redirects the user to another asp.net application after
adding a custom header to the request stream eg. ValidatedUserName.

When we add header to current request object and then redirect using
server.transfer() we don't get this header on the target aspx page (yes, we
tried after setting the preserve headers to true), what we think the cause
can be is that when server.transfer is called it creates a new request to the
target server and the headers that we added in the current request are not
available in that request.

We also tried adding headers in request and then getting the response after
creating a WebResponse object via WebRequest.Create(<url>) (this time it was
just a test to see if the headers were actually added when the request was
created, not redirecting as actually needed) and viola we got the header in
the target application (but this didn't helped much as what we need is a
redirect with header).

Please advice how can we do a redirect to a different webapplication by
adding custom header in request stream (there has to be a overwrite
somewhere, so that we can do what we need here).

If you're looking at the same method I am, there isn't a method which
has a "preserve headers" - only "preserve form" which is somewhat
different.

I'm afraid I'm far from an ASP.NET expert - I suggest you ask on the
ASP.NET newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top