How to capture individual Request

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • FD

    How to capture individual Request

    For performance reason, the follwoing code (C#) to capture
    all the Request collection contexts is NOT recommended:

    string ID = Request.QuerySt ring["ID"];

    But how to Capture the individual Request properties
    needed in the application?

    Thanks,
    FD

  • Bill Priess

    #2
    Re: How to capture individual Request

    For what performance reason? The QueryString collection is a
    NameValueCollec tion class which utilizes property indexers. There is a
    slight performance hit when querying a value using a string (becuase of the
    collection having to basically iterate over the collection and do a
    BinaryCompare on each object to the indexer that was passed). But, overall,
    there is no performance hit what-so-ever. If you are worried about it
    though, use the ordinal index of the property that you want to return.

    IE:

    querystring: http://localhost/webform1.aspx?name=test&value=me

    string name = Request.QuerySt ring[0];
    string value = Request.QuerySt ring[1];

    This might be ***slightly*** faster than using

    string name = Request.QuerySt ring["name"];
    string value = Request.QuerySt ring["value"];

    But, if you even notice a difference, I would be surprised. Only if you had
    a really large QueryString collection would you notice a performance gain.

    HTH,

    Bill P.

    "FD" <fding@allstate .com> wrote in message
    news:409301c3aa c6$1c76f370$a60 1280a@phx.gbl.. .[color=blue]
    > For performance reason, the follwoing code (C#) to capture
    > all the Request collection contexts is NOT recommended:
    >
    > string ID = Request.QuerySt ring["ID"];
    >
    > But how to Capture the individual Request properties
    > needed in the application?
    >
    > Thanks,
    > FD
    >[/color]


    Comment

    Working...