Forms Validation exception: System.Web.HttpRequestValidationException with '&#' in password RRS feed

  • Question

  • User-1188570427 posted

    Has anyone seen an issue with using


    within a password?

    We are seeing an issue where if the password has &# at the front, middle, end of the password it fails with this:

    System.Web.HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client 

    Do we need to add 'AllowHtml' attribute to our password and confirm password?

    We've tried a number of combinations from the initial password that failed from the user.

    Thursday, October 15, 2020 8:31 PM


  • User1535942433 posted

    Hi tvb2727,

    As far as I think, you can't filter random input for dangerous characters, because any character may be dangerous under the right circumstances. You should encode at the point where some specific characters may become dangerous because they cross into a different sub-language where they have special meaning. When you write a string to HTML, you should encode characters that have special meaning in HTML, using Server.HtmlEncode. If you pass a string to a dynamic SQL statement, you should encode different characters (or better, let the framework do it for you by using prepared statements or the like).

    When you are sure you HTML-encode everywhere you pass strings to HTML, then set ValidateRequest="false" in the <%@ Page ... %> directive in your .aspx file(s).

    In .NET 4 you may need to do a little more. Sometimes it's necessary to also add <httpRuntime requestValidationMode="2.0" /> to web.config.

    More details,you could refer to below articles:



    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2020 5:45 AM