Adding Headers in ASP.NET on vista

M

MikeB

Hi,

I had the following code running fine on my xp box. Then, I got a
vista box and now I get a "PlatformNotSupportedException" when I try
to add the header. I do know that now in IIS7 there are different ways
to do things, but I have the issue of deploying to IIS6 servers.

//get a reference
NameValueCollection headers =
HttpContext.Current.Request.Headers;
//get a type
Type t = headers.GetType();
//get the property
PropertyInfo p = t.GetProperty("IsReadOnly",
BindingFlags.Instance | BindingFlags.IgnoreCase
| BindingFlags.NonPublic |
BindingFlags.FlattenHierarchy);
//unset readonly
p.SetValue(headers, false,null);

//add a header
//This breaks in vista
headers.Add("SID", "1234"));

It blows up on the last line. I am using the built in webserver for vs.
2005, but I do have IIS installed on vista.
This code is just in an http module that gets ran as a request is
coming in. Again, it worked fine on my xp box. Any ideas are
appreciated.
 
M

Mark S. Milley, MCSD (BinarySwitch)

The request collection is read only; you simply can't change the
request from your client, and I'm not sure why you would want to, and
I'm not sure why this ever worked, as you indicate.

You can edit the _response_, but not the request.

Good Luck,

-Mark
 
M

MikeB

The request collection is read only; you simply can't change the
request from your client, and I'm not sure why you would want to, and
I'm not sure why this ever worked, as you indicate.

You can edit the _response_, but not the request.

Good Luck,

-Mark


I am using an HTTPModule to analyze incoming urls and pass a variable
along to the app. I had been using headers because it seemed fairly
clean, but I am open to any suggestions at all.

1) I need to look at a url like:
www.xyz.com/madeUpDirectory/
2) I need to find an ID based on madeUpDirectory
3) I need to pass that ID along to my app.

The user still sees
www.xyz.com/madeUpDirectory, but that in fact doesn't exist.

I had it all worked out using xp/Server 2003, but again vista blows
up.

Do you have an idea for the most appropriate way to pass this data
along? Request.QueryString is read only as well.

Thanks
-Mike
 
M

Mark S. Milley, MCSD (BinarySwitch)

Hi Mike -

Just do a Response.Redirect. The user shouldn't see the difference on
their end.

Response.Redirect(string.format("pathtoredirectto?myarg={0}",myparam)

However, out of curiosity, why even pass this along in the
querystring? Can't you just as easily extrapolate the request from the
code that is going to use the resultant variable?

In other words, iin your sub, instead of looking for
request.querystring("myarg"), determine, at that point, what the
requesting path is. If that's inconvenient, you can always create a
private member variable to hold the parameter, and set the value on
the page_load to reuse throughout the page.

Good luck,

-Mark
 
M

MikeB

Mark,
I think I will go with your last suggestion. I have an odd situation
where I have to parse the url and sometimes rewrite it and sometimes
do nothing. The only downside I can see is that I have to parse the
url twice: 1) parse it to see if I need to do anything, 2) if I
rewrote the url then reparse to get the variable info.

I had hoped to avoid this by setting the header, but it certainly
isn't the end of world if I can't. I appreciate you taking the time to
offer suggestions. I think I will take the last approach you
mentioned.

Thanks again.
-Mike
 

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

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top