Click here to Skip to main content
11,925,851 members (62,136 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked

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()
            return base.DeterminePostBackMode();
        catch(HttpRequestValidationException ex) {
//            do the handling here
return null;


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


About the Author

M I developer
Technical Lead 10pearls
United States United States
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 | :)
Have done Master and Bachelors of Computer Science from Karachi University Pakistan
Anything I found interesting technically or non-technically so nothing specific Wink | ;)

You may also be interested in...

Comments and Discussions

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

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web02 | 2.8.151126.1 | Last Updated 6 Nov 2011
Article Copyright 2011 by M I developer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid