Here we mainly discuss the problem of numeric parameter values. The general practice is to convert the data type and use try catch to catch exceptions,
However, this method is not optimal in terms of performance and actual effect. In. NEt 2.0, you can directly use the new
The introduced TryParse method is used to implement
For example:
Int I = 0;
Int j = 0;
Bool IsPre1 = Int32.TryParse ("30", out I );
Bool IsPre2 = Int32.TryParse ("12 s", out j );
// After execution, I = 30, j = 0; IsPre1 = true, IsPre2 = false;
Available
Int requestString = 0;
If (Int32.TryParse (Request ["parameter name"], out requestString) to determine, if the conversion is successful (it indicates that the conversion is successful)
Continue to execute the program. Otherwise, the execution is stopped. This effectively prevents malicious parameter IDs from being passed in.