Processing of ASP. NET page Parameters

Source: Internet
Author: User

Processing of ASP. NET page parameters? No one will!

Isn't it like request. querystring ["ID?

However, the following sentence is so simple and clear that sometimes there are problems:

int Id = (Request.QueryString["Id"] != null) ? Convert.ToInt32(Request.QueryString["Id"]) : 0;

Why? Sometimes, for various reasons, the user's linked address may be followed by some strange symbols, such as # (the browser will change to % 23 After encoding, then the above statement will report an error.

Frequent errors may make people feel unreliable. So it is necessary to handle:

// Sometimes, some access address parameters are suffixed with various odd characters, causing page errors and removing them to improve the experience of protected int getintparam (string PARAM) {return convert. toint32 (_ getclearparam (PARAM);} protected int64 getint64param (string PARAM) {return convert. toint64 (_ getclearparam (PARAM);} string _ getclearparam (string PARAM) {RegEx r = new RegEx (@"(? <ID> \-? \ D +) ", regexoptions. ignorecase); try {return r. match (PARAM ). result ("$ {ID}") ;}catch {Throw new exception ("parameter error:" + PARAM );}}

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.