I’ve got this simple table. One field inside it is called Content with the Nvarchar(max).
If I edit that field directly in the database using SQL Server Management, adding the following text below, it stores it fine.
Text:
Do you open the menu at a restaurant ever expanding multi-cultural tourist hub, Chinatown has a lot to offer to meet your culinary desires, from China and beyond.<br /></br>This tour will be the first in a series the food.
However if I try to submit the same text above using an ASPX page webform to the database, I get the error below, I assume because of the 2 <br /> code
A potentially dangerous Request.Form value was detected from the
client (tbTourDetails=”…nd beyond.
This tour…”).
How can I get around this so I can have a webform that submit partly HTML to my database?
Regards
Tea
Since you are trying to store html code, you need to add requestValidationMode=”2.0″ to the httpRuntime configuration section of the web.config.
Now encode it before storing:
And decode it for displaying as a text:
References:
HtmlEncode Method
HtmlEncode, HtmlDecode