Click here to Skip to main content
Click here to Skip to main content

Tagged as

Try catch block around "A potentially dangerous Request.Form"

, 6 Nov 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Try catch block around "A potentially dangerous Request.Form"
Sometimes, the user enters HTML tags or malicious characters in text fields. By default, ASP.NET blocks those characters and shows the following error:
 
A potentially dangerous Request.Form value was detected from the client (aa="<te>").
 
If we want to show a user friendly message on the raise of this exception, then we have to catch that particular type of exception. But the question is, from where we can catch that exception where we place our try catch block to catch this type of exception. I have seen lot of solutions which are mostly using global.asax where they handle this exception on Application_Error. But what if we want to catch this type of error on Page. Here is the solution:
 
protected override System.Collections.Specialized.NameValueCollection DeterminePostBackMode()
    {
       try
        {
            return base.DeterminePostBackMode();
        }
        catch(HttpRequestValidationException ex) {
           
//            do the handling here
            
        }
return null;
    }

License

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

Share

About the Author

M I developer
Technical Lead 10pearls
United States United States
<Profile>
<Profession>
I am a Software Engineer from Karachi Pakistan, Being a programmer obviously I love to code but I love to code that adds something new in my knowledge else I do copy paste usually Smile | :)
</Profession>
<Education>
Have done Master and Bachelors of Computer Science from Karachi University Pakistan
</Education>
<Interests>
Anything I found interesting technically or non-technically so nothing specific Wink | ;)
</Interests>
</Profile>

Comments and Discussions

 
QuestionNot working for me PinmemberEitan.Aviran6-Sep-12 3:11 
GeneralHave you tested this with ASP.NET 4.0? Request validation no... PinmemberRichard Deeming8-Nov-11 8:56 
GeneralRe: I havn't tested it on .Net 4.0 but it seems pretty logical t... PinmemberM I developer8-Nov-11 21:19 
GeneralThanks, buddy! Vote of 5! PinmemberCarstenV27-Nov-11 20:20 
GeneralRe: Thanx PinmemberM I developer8-Nov-11 21:11 
GeneralOr you could turn validation off and do your own validation ... PinmemberHenry.Ayoola3-Nov-11 5:15 
GeneralRe: but in that case you have to check every input for malicious... PinmemberM I developer3-Nov-11 20:11 
GeneralReason for my vote of 5 Been looking for this, thanks! Pinmemberjim lahey3-Nov-11 4:24 
Reason for my vote of 5
Been looking for this, thanks!
GeneralRe: Thanx PinmemberM I developer8-Nov-11 21:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411022.1 | Last Updated 6 Nov 2011
Article Copyright 2011 by M I developer
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid