If the MVC request parameter contains HTML, the validation exception ("a potentially dangerous request. form value was detected from

Source: Internet
Author: User

When the client in MVC transmits a value to the server, if the client string contains "</>", it will report "potential danger "(

"A potentially dangerous request. form value was detected from the client".

For example, the request. form value is detected in the client ("test <br/> TTT.

 

Solution:

Add the [validateinput (false)] attribute to the corresponding action to solve the problem and remove verification.

However, it seems that the. NET 4.0 attribute does not work, so you can add it to the systerm. Web node in Web. config.

<Httpruntime requestvalidationmode = "2.0" type = "codeph" text = "/codeph"/>

 

Solution B:

Method A is a little troublesome, and there is a better solution in mvc3,CodeAs follows:

Namevaluecollection paramcoll = NULL; // comment strings are HTML strings, so get the unvalidate version here if (0 = string. compare (request. httpmethod, "Post", true) {paramcoll = new formcollection (request. unvalidated (). form);} else if (0 = string. compare (request. httpmethod, "get", true) {paramcoll = new namevaluecollection (request. unvalidated (). querystring);} else {paramcoll = request. params;

}

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.