In PHP I can use the following to stop HTML from rendering, so it actually displays html as text on the web page:
$html = "<div开发者_JAVA技巧>Some text</div>";
echo htmlentities($html);
How do I do the same with asp.net pages (vb.net). I am using .NET 3.5.
You could try:
var html = @"<div>Some text</div>";
Response.Write(Server.HtmlEncode(html));
which is the exact translation of your snippet.
BTW, you can find more info on Server.HtmlEncode
here.
You could use HttpServerUtility.HtmlEncode
for this:
<%= Server.HtmlEncode("<div>Some text</div>") %>
In .NET 4 you could use a shorthand for this:
<%: "<div>Some text</div>" %>
Server.HtmlEncode("`<div>Some text</div>`");
精彩评论