Solution to Request. QueryString exceptions

Source: Internet
Author: User

In web requests, we often need to use the page to pass values, but sometimes exceptions occur if you do not pay attention to them.

For example, the address of a page is ../index. aspx.

Its background file contains the statement for processing the passed value: if (Request. queryString ["TypeID"] = null | Request. queryString ["TypeID"]. toString () = "")

When your address.../index. aspx? If TypeID = 1, the system runs normally without any exception.

However, when your address is:

.. /Index. when aspx is used, the if (Request. queryString ["TypeID"]. toString () = "" | Request. queryString ["TypeID"]. toString () = null)

The exception occurs. What is this?

The main reason is the Request. queryString ["TypeID"] is an object that is the same as null, When you Request. queryString ["TypeID"]. toString () = "", because the Request. queryString ["TypeID"] This object does not exist at all and will not be converted to "". Therefore, when you are not sure whether there is a page value transfer, we 'd better judge whether the passed object does not exist and then process it as a string so that no exception will occur.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.