Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:19:36+00:00 2026-05-28T13:19:36+00:00

I searched SO and found similar questions, but none compared all three. That surprised

  • 0

I searched SO and found similar questions, but none compared all three. That surprised me, so if someone knows of one, please point me to it.

There are a number of different ways to parse the query string of a request… the “correct” way (IMO) should handle null/missing values, but also decode parameter values as appropriate. Which of the following would be the best way to do both?

Method 1

string suffix = Request.QueryString.Get("suffix") ?? "DefaultSuffix";

Method2

string suffix = Request.QueryString["suffix"] ?? "DefaultSuffix";

Method 3

NameValueCollection params = HttpUtility.ParseQueryString(Request.RawUrl);    
string suffix = params.Get("suffix") ?? "DefaultSuffix";

Method 4

NameValueCollection params = HttpUtility.ParseQueryString(Request.RawUrl);    
string suffix = params["suffix"] ?? "DefaultSuffix";

Questions:

  1. Would Request.QueryString["suffix"] return a null if no suffix was specified?
    (Embarrassingly basic question, I know)

  2. Does HttpUtility.ParseQueryString() provide any extra functionality over accessing Request.QueryString directly?

  3. The MSDN documentation lists this warning:

    The ParseQueryString method uses query strings that might contain user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

    But it’s not clear to me if that means ParseQueryString() should be used to handle that, or is exposed to security flaws because of it… Which is it?

  4. ParseQueryString() uses UTF8 encoding by default… do all browsers encode the query string in UTF8 by default?

  5. ParseQueryString() will comma-separate values if more than one is specified… does Request.QueryString() do that as well, or what happens if it doesn’t?

  6. Which of those methods would correctly decode “%2b” to be a “+”?

Showing my Windows development roots again… and I would be a much faster developer if I didn’t wonder about these things so much… : P

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:19:37+00:00Added an answer on May 28, 2026 at 1:19 pm

    Methods #1 and #2 are the same thing, really. (I think the .Get() method is provided for language compatibility.)

    ParseQueryString returns you something that is the functional equivalent of Request.Querystring. You would usually use it when you have a raw URL and no other way to parse the query string parameters from it. Request.Querystring does that for you, so in this case, it’s not needed.

    1. You can’t leave off "suffix". You either have to pass a string or an index number. If you leave off the [] entirely, you get the whole NameValueCollection. If you mean what if "suffix" was not one of the QueryString values then yes; you would get null if you called Request.QueryString["suffix"].

    2. No. The most likely time you would use it is if you had an external URL and wanted to parse the query string parameters from it.

    3. ParseQueryString does not handle it… neither does pulling the values straight from Request.QueryString. For ASP.NET, you usually handle form values as the values of controls, and that is where ASP.NET usually ‘handles’ these things for you. In other words: DON’T TRUST USER INPUT Ever. No matter what framework is doing what ever for you.

    4. I have no clue (I think no). However, I think what you are reading is telling you that ParseQueryString is returning UTF-8 encoded text – regardless if it was so encoded when it came in.

    5. Again: ParseQueryString returns basically the same thing you get from Request.QueryString. In fact, I think ParseQueryString is used internally to provide Request.QueryString.

    6. They would produce the equivalent; they will all properly decode the values submitted. If you have URL: http://site.com/page.aspx?id=%20Hello then call Request.QueryString["id"] the return value will be " Hello", because it automatically decodes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one has me stumped. I've searched and found similar questions but I can't
I've searched for similar questions to mine here, but haven't found a thread that
I searched through StackOverFlow and found similar questions but nothing that answered my particular
(I've searched for something similar, but haven't found anything that matches and/or works) I
I searched and found three fairly good posts but all of them were animating
I have searched and found a lot of different things but none that actually
I have checked the questions with similar titles, and searched, but found nothing. But
I searched similar questions but never found a proper answer. I am making app
I've searched SO but not found similar questions as I'm not sure how to
I've searched for similar questions but still have not found a solution as to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.