Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to store BCA&# entered in textbox in asp.net and sql server. But i got error System.Web.HttpRequestValidationException
A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$txtName="BCA&#").

What I have tried:

i found the issue is &#. when &# is written together it is causing issue. How can i store this input without using ValidateRequest="false" at page directive.
. I tried
Server.HtmlEncode(txtName.Text.Trim())
but is not working too.
Posted
Updated 5-Mar-17 22:22pm
v5

Quote:
How can i store this input without using ValidateRequest="false" at page directive.


You can't, you're going to have to disable validation for that page and ensure your code is not vulnerable to XSS attacks etc.
 
Share this answer
 
Comments
xpertzgurtej 6-Mar-17 4:34am    
i don't want to set ValidateRequest="false" because it will allow XSS attacks. What to do in this case? how to ensure this?
F-ES Sitecore 6-Mar-17 4:44am    
Just make sure your code is not vulnerable to XSS attacks, it is perfectly possible to do this. Just ensure any data that comes from the user is not written directly to the output html in a non-encoded form.
xpertzgurtej 6-Mar-17 5:20am    
So what should i do now? Should i use ValidateRequest="false" at page directive or something else?
F-ES Sitecore 6-Mar-17 5:23am    
Yes you have to use ValidateRequest="false"
xpertzgurtej 6-Mar-17 6:48am    
:(
Add these two under <system.web> in web.config file

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

if the tags are already present, then try to update only the properties to it.
 
Share this answer
 
Comments
ZurdoDev 6-Mar-17 8:07am    
This will do it for all pages which is not a good idea. You should do this in a location tag.
Karthik_Mahalingam 6-Mar-17 8:14am    
reply with an example please, I am unaware of this :(
ZurdoDev 6-Mar-17 8:19am    
https://msdn.microsoft.com/en-us/library/b6x6shw7(v=vs.71).aspx

It's a way to have a setting only affect a certain page or folder.
Karthik_Mahalingam 6-Mar-17 8:28am    
Thanks for the info, i will consider this in future.

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