Adding Headers in ASP.NET on vista

Discussion in 'ASP .Net' started by MikeB, Jul 6, 2007.

  1. MikeB

    MikeB Guest

    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.
     
    MikeB, Jul 6, 2007
    #1
    1. Advertising

  2. 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
     
    Mark S. Milley, MCSD (BinarySwitch), Jul 8, 2007
    #2
    1. Advertising

  3. MikeB

    MikeB Guest

    On Jul 7, 11:20 pm, "Mark S. Milley, MCSD (BinarySwitch)"
    <> wrote:
    > 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
     
    MikeB, Jul 9, 2007
    #3
  4. 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
     
    Mark S. Milley, MCSD (BinarySwitch), Jul 9, 2007
    #4
  5. MikeB

    MikeB Guest

    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


    On Jul 9, 10:10 am, "Mark S. Milley, MCSD (BinarySwitch)"
    <> wrote:
    > 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 therequestfrom the
    > code that is going to use the resultant variable?
    >
    > In other words, iin your sub, instead of looking forrequest.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
     
    MikeB, Jul 10, 2007
    #5
  6. Hi Mike -

    Glad I could help...

    -Mark
     
    Mark S. Milley, MCSD (BinarySwitch), Jul 16, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dont bother
    Replies:
    0
    Views:
    812
    dont bother
    Mar 3, 2004
  2. Michael
    Replies:
    5
    Views:
    918
    Bjoern Schliessmann
    Nov 3, 2007
  3. Jason Cavett

    JTable Headers and Windows Vista

    Jason Cavett, Apr 15, 2008, in forum: Java
    Replies:
    4
    Views:
    387
    David A. Redick
    Apr 25, 2008
  4. Phil
    Replies:
    4
    Views:
    687
    Gabriel Genellina
    Jan 17, 2010
  5. Ian
    Replies:
    2
    Views:
    1,964
Loading...

Share This Page