How to capture individual Request

  • Thread starter Thread starter FD
  • Start date Start date
F

FD

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

string ID = Request.QueryString["ID"];

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

Thanks,
FD
 
For what performance reason? The QueryString collection is a
NameValueCollection 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.QueryString[0];
string value = Request.QueryString[1];

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

string name = Request.QueryString["name"];
string value = Request.QueryString["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.
 
Back
Top