So right now I’m using something like this in C#:
Response.Write(Server.HtmlEncode(line));
This will grab a line from a text file and display the stuff on screen – it works. My goal was to have the lines from the text file show something like this (HTML formatting in lines of text file):
<a href='http://www.url.com' target='_blank'>Link</a><br><br><!--info-->
Unfortunately, for some reason the < and > are being converted to < and > before it gets turned into HTML, which exposes all the HTML code as text and simply doesn’t work. I have tried looking into the WebBrowser control and stuff but I don’t understand what I’m supposed to do. For example, I tried this from a site:
WebBrowser browser = new WebBrowser();
browser.Navigate("about:blank");
browser.Document.Write(Server.HtmlEncode(line));
…but it didn’t work. I’m looking for something very simple and with a clear example I can mimic, if possible. Thanks! I will make sure to select an answer too.
Other than that you are explicitly encoding the
<and>brackets into<and it’s counterpart, I don’t see any error.Drop the
Server.HtmlEncode()part and it should work.Server.HtmlEncode()will explicitly encode everything into so-called “entities”, which are those<codes. It is usually used to protect yourself from user-entered raw strings that should not modify your site’s behaviour.