Use the merge operator in. NET to obtain parameters in the URL.

Source: Internet
Author: User

GET the GET parameter in the URL. No matter what language is used to develop the website, the code is almost required. However, to obtain a URL parameter, you must first determine whether the parameter exists. If the parameter exists, the parameter is taken out. If the parameter does not exist, another value is used. This operation is called a merge operation, which is very common in JavaScript. | two vertical bars mean this. Today, I accidentally saw the merge operator in ASP. NET. What is different from JavaScript is that it is used in. NET ?? Two question marks. As a result, we immediately thought we could use it to get URL parameters, greatly streamlining the Code:

Page_Load (type = Request []? ; Keyword = Request []? ;}

Paste the previous code for comparison:

. IsNullOrEmpty (Request [? Request [. IsNullOrEmpty (Request [? Request [

In contrast, it is quite concise.

Of course, this is just a simple example. How to improve it and prevent illegal parameters in URLs must be improved in different projects. For more information, see the reference document "merge operators" in MSDN.

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.