469,575 Members | 1,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Add the headers to httpwebrequest/httpwebresponse from .net code

how to add the headers to httpwebrequest/httpwebresponse from .net code ?
Jul 21 '05 #1
4 8972
Vivek <Vi***@discussions.microsoft.com> wrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2


"Jon Skeet [C# MVP]" wrote:
Vivek <Vi***@discussions.microsoft.com> wrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

thanks Jon
can you send me the code?
Jul 21 '05 #3
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!

"Jon Skeet [C# MVP]" wrote:
Vivek <Vi***@discussions.microsoft.com> wrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #4
Vivek <Vi***@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Mike Cronin via DotNetMonster.com | last post: by
2 posts views Thread by Dunc | last post: by
5 posts views Thread by rlueneberg | last post: by
reply views Thread by Piotrekk | last post: by
1 post views Thread by ALA | last post: by
15 posts views Thread by Nightcrawler | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.