Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I did search and read so many posts talk about the error message "A potentially dangerous request.querystring value was detected from the client". But, I believe my problem is totally different.

In my web.config file, I already defined two keys below:

HTML
<httpRuntime requestValidationMode="2.0" />
<pages validateRequest="false" />


So, if I publish my project (asp.net webform) without using Precompile option, everything will work smoothly as my expected.

However, if I publish my project with Precompile option (precompile all site), the error above will always occur when I submit a form.

The submit form is so simple, it contains one input text control and one submit button. And my input text was
<script>alert(1)</script>


So, my question is why this issue happens with precompile publish build? Any advice for me?

What I have tried:

Put two keys below in web.config does not solve the problem.
<httpRuntime requestValidationMode="2.0" />
<pages validateRequest="false" />
Posted
Updated 6-Jun-18 22:44pm
Comments
Richard Deeming 7-Jun-18 11:15am    
This thread from 2010[^] suggests that the validateRequest setting is ignored when you precompile the site, unless you also select the "Allow this precompiled site to be updatable" option.

If you need to access the request data without triggering the validation, use the Request.Unvalidated collections. NB: This could leave your site vulnerable to XSS unless you properly encode any values read from these collections before you display them.

1 solution

You are passing HTML containing a script tag from your form. Such is potentially dangerous. The goal is not to get rid of the error message by setting some options but to avoid that such dangerous data is passed.

This can be done by encoding the data upon submission and decoding before processing. The common method is to use the HttpServerUtility.HtmlEncode Method (String) (System.Web)[^]. But see also ScottGu's Blog - New <%: %> Syntax for HTML Encoding Output in ASP.NET 4 (and ASP.NET MVC 2)[^].
 
Share this answer
 
Comments
nkphuc700 8-Jun-18 0:22am    
HtmlEncode() already applied in my code.

But, the error only happens with the publish build using precompile. While it works normally with the publish build without using precompile.
Jochen Arndt 8-Jun-18 2:36am    
"HtmlEncode() already applied in my code"

How could I know? You did not mentioned it in your question.

For the precompiled problem:
See Richards comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900