Every time a user posts something containing
> in a page in my web application, I get this exception thrown.
I don't want to go into the discussion about the smartness of throwing an exception or crashing an entire web application because somebody entered a character in a text box, but I am looking for an elegant way to handle this.
Trapping the exception and showing
An error has occurred please go back and re-type your entire form again, but this time please do not use <
doesn't seem professional enough to me.
Disabling post validation (
validateRequest="false") will definitely avoid this error, but it will leave the page vulnerable to a number of attacks.
Ideally: When a post back occurs containing HTML restricted characters, that posted value in the Form collection will be automatically HTML encoded.So the
.Text property of my text-box will be
something & lt; html & gt;
Is there a way I can do this from a handler?
I use the
<pre> tag in my blog to post code. I know I have to change
>. Are any other characters I need to escape for correct html?
I want to convert
& to &,
" to " etc.Is there a function in c# that could do that without writing all the options manually?
The reason I think I need it, is because I'm displaying text I get from websites in a Windows 8 store app. E.g.
é should become
Or is there a better way? I'm not displaying websites or rss feeds, but just a list of websites and their titles.
I am trying to encode special character in html attribute using C#
When I encode this following string
var encode1= HttpUtility.HtmlEncode("Student on \" On the Rise \"");
the encoding generates the correct output, like this:
Student on " On the Rise "
The browser encodes the
& and again and generate wrong encoding as follow
<meta property="og:title" content="Student on &quot; On the Rise &quot;" />
How can I tell the browser not to encode the
& character again?