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 );}}