How to prevent malicious value passing by parameter IDS

Source: Internet
Author: User
Tags try catch

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.

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.