Request.Querystring handling without name/value pairs

Discussion in 'ASP .Net' started by =?Utf-8?B?V2lsbCBaYWNobWFubg==?=, Aug 1, 2007.

  1. I am working with an old web application writing new ASP.NET code to replace
    functions previously handled by a monolithic ISAPI dll and intercepting some
    calls to it. It uses, however, a query string made up of isolated values
    (i.e. <value>&<value>& . . .) rather than <name>=<value> pairs.

    I have figured out how to get the entire string in order to parse it, but I
    have not yet figured out an easy way (easier, that is, than letting it throw
    an exception and handling it) to check to make sure the string is not null.

    Can anyone point me in the right direction for how best to do this?

    Also, if anyone can suggest an easier way to obtain the values than getting
    the whole string and parsing it 'manually' that would be helpful, too.

    I know this ought to be quite simple once one knows how, but I have been
    having a very hard time finding information on how to do it. Everything I
    have found concerning Request.QueryString seems to take it for granted that
    all query strings are going to be formated as name/value pairs rather than as
    an ordered string of values.

    Thanks!

    All the best,

    will

    --
    William F. Zachmann
    Canopus Research Inc.
    http://www.canopusresearch.com
    =?Utf-8?B?V2lsbCBaYWNobWFubg==?=, Aug 1, 2007
    #1
    1. Advertising

  2. Will,
    I am afraid that in this case you don't have much of a choice other than to
    intercept and grab this "pseudo" querystring. I hope there's a ? question
    mark there so you can find the beginning of it. Then, you can String.Split to
    an array of values based on the & character as the delimiter.
    -- Peter
    Recursion: see Recursion
    site: http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    bogMetaFinder: http://www.blogmetafinder.com



    "Will Zachmann" wrote:

    > I am working with an old web application writing new ASP.NET code to replace
    > functions previously handled by a monolithic ISAPI dll and intercepting some
    > calls to it. It uses, however, a query string made up of isolated values
    > (i.e. <value>&<value>& . . .) rather than <name>=<value> pairs.
    >
    > I have figured out how to get the entire string in order to parse it, but I
    > have not yet figured out an easy way (easier, that is, than letting it throw
    > an exception and handling it) to check to make sure the string is not null.
    >
    > Can anyone point me in the right direction for how best to do this?
    >
    > Also, if anyone can suggest an easier way to obtain the values than getting
    > the whole string and parsing it 'manually' that would be helpful, too.
    >
    > I know this ought to be quite simple once one knows how, but I have been
    > having a very hard time finding information on how to do it. Everything I
    > have found concerning Request.QueryString seems to take it for granted that
    > all query strings are going to be formated as name/value pairs rather than as
    > an ordered string of values.
    >
    > Thanks!
    >
    > All the best,
    >
    > will
    >
    > --
    > William F. Zachmann
    > Canopus Research Inc.
    > http://www.canopusresearch.com
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Aug 1, 2007
    #2
    1. Advertising

  3. Peter,

    Thanks much for trying to help. Yes, the query string does use the &
    character as a delimiter between values. I guess I was not as clear as I
    might have been. I am not having any problem getting the entire query
    string. I am able to do that by simply using a zero index as follows:

    string s = Request.QueryString[0];

    I can then 'manually' parse the string without too much difficulty (although
    it would be nice to have an easier way to do it.

    My main problem, though, is that the above code fails (i.e. generates an
    exception) if there is no query string at all. If the query string were
    organized as name/value pairs, I could test for != null for a specific named
    parameter before trying to read it. What I am looking for, though, is a way
    to test to see if there is anything there at all.

    I have tried checking (I think) to see if (Request.QueryString[0] != null)
    but (unless I mis-remember what happened) that also throws an exception when
    the CLR tries to resolve "Request.QueryString[0] prior to making the
    comparison. So that doesn't work.

    Obviously, I could just put the thing in a try block and intercept the
    exception, but I have a hard time believing there isn't a simpler way to do
    it. That is the key info I am seeking (i.e. how to do that).

    The thought has occurred to me that maybe I need to move up the inheritance
    heirarchy to, say, the HttpRequest class, prior to whatever builds the
    name/value pair collection, but I am not very familiar with the details of
    how all that works, so I figured I would ask here before spending a lot more
    time combing through the documentation to try to figure out if I could do it
    that way.

    Anyway, I do very much appreciate your getting back to me!

    All the best,

    will


    --
    William F. Zachmann
    Canopus Research Inc.
    http://www.canopusresearch.com


    "Peter Bromberg [C# MVP]" wrote:

    > Will,
    > I am afraid that in this case you don't have much of a choice other than to
    > intercept and grab this "pseudo" querystring. I hope there's a ? question
    > mark there so you can find the beginning of it. Then, you can String.Split to
    > an array of values based on the & character as the delimiter.
    > -- Peter
    > Recursion: see Recursion
    > site: http://www.eggheadcafe.com
    > unBlog: http://petesbloggerama.blogspot.com
    > bogMetaFinder: http://www.blogmetafinder.com
    >
    >
    >
    > "Will Zachmann" wrote:
    >
    > > I am working with an old web application writing new ASP.NET code to replace
    > > functions previously handled by a monolithic ISAPI dll and intercepting some
    > > calls to it. It uses, however, a query string made up of isolated values
    > > (i.e. <value>&<value>& . . .) rather than <name>=<value> pairs.
    > >
    > > I have figured out how to get the entire string in order to parse it, but I
    > > have not yet figured out an easy way (easier, that is, than letting it throw
    > > an exception and handling it) to check to make sure the string is not null.
    > >
    > > Can anyone point me in the right direction for how best to do this?
    > >
    > > Also, if anyone can suggest an easier way to obtain the values than getting
    > > the whole string and parsing it 'manually' that would be helpful, too.
    > >
    > > I know this ought to be quite simple once one knows how, but I have been
    > > having a very hard time finding information on how to do it. Everything I
    > > have found concerning Request.QueryString seems to take it for granted that
    > > all query strings are going to be formated as name/value pairs rather than as
    > > an ordered string of values.
    > >
    > > Thanks!
    > >
    > > All the best,
    > >
    > > will
    > >
    > > --
    > > William F. Zachmann
    > > Canopus Research Inc.
    > > http://www.canopusresearch.com
    =?Utf-8?B?V2lsbCBaYWNobWFubg==?=, Aug 2, 2007
    #3
    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. I R BABOON
    Replies:
    0
    Views:
    308
    I R BABOON
    Oct 21, 2003
  2. TR
    Replies:
    3
    Views:
    1,205
  3. Mehdi
    Replies:
    6
    Views:
    36,076
    sloan
    Apr 6, 2006
  4. I R BABOON

    Handling name value pairs in a web service

    I R BABOON, Oct 21, 2003, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    95
    john bailo
    Oct 22, 2003
  5. John Davis
    Replies:
    2
    Views:
    375
    Dave Anderson
    Aug 18, 2003
Loading...

Share This Page