Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am getting potential dangerous request. From value was detected issue in asp.net. i have set the Improper Error Handling option in web.config. i cannot add requestvalidationmode=2.0 in config. If javascript entry in the input fields it should go to error page. But in email configuration page where email body will contain html tag values. i gave validaterequest="false" and enableventvalidate=false for this page. But still this page is going to error Page

What I have tried:

web.config
<customErrors mode="On" defaultRedirect="CustomError.aspx" redirectMode="ResponseRewrite">
      <error statusCode="404" redirect="/CustomError.aspx"/>
    </customErrors>

<httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
      <remove statusCode="502" subStatusCode="-1" />
      <error statusCode="502" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="501" subStatusCode="-1" />
      <error statusCode="501" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="500" subStatusCode="-1" />
      <error statusCode="500" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="403" subStatusCode="-1" />
      <error statusCode="403" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="400" subStatusCode="-1" />
      <error statusCode="400" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="401" subStatusCode="-1" />
      <error statusCode="401" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="405" subStatusCode="-1" />
      <error statusCode="405" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="406" subStatusCode="-1" />
      <error statusCode="406" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
      <remove statusCode="412" subStatusCode="-1" />
      <error statusCode="412" prefixLanguageFilePath="" path="./CustomError.aspx" responseMode="Redirect" />
    </httpErrors>
Posted
Updated 16-Nov-21 23:16pm

1 solution

Request Validation in ASP.NET | Microsoft Docs[^]

To disable request validation for a specific WebForms page, set the ValidateRequest property to false:
ASPX
<%@ Page ValidateRequest="false" %>
To disable it for a specific control, set the ValidateRequestMode property[^] on that control:
ASPX
<asp:TextBox id="txtBody" runat="server" ValidateRequestMode="Disabled" />

For MVC, use [ValidateInput(false)] on the action, or [AllowHtml] on the model property.

For code which directly accesses the form/querystring collections, use Request.Unvalidated().Form or Request.Unvalidated().QueryString to retrieve the values without triggering the request validation.
 
Share this answer
 

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