{"id":159,"date":"2010-12-06T10:08:00","date_gmt":"2010-12-06T04:38:00","guid":{"rendered":"https:\/\/ashokaon.tech\/blog\/?p=159"},"modified":"2020-07-18T01:13:05","modified_gmt":"2020-07-17T19:43:05","slug":"asp-net-4-new-feature-html-encode-shorthand","status":"publish","type":"post","link":"https:\/\/ashokaon.tech\/blog\/asp-net-4-new-feature-html-encode-shorthand\/","title":{"rendered":"A new feature in ASP.NET 4: Shorthand syntax for Html Encoding"},"content":{"rendered":"<p><span style=\"font-size: 10px;background-color:#FFFF99;display:block\">(Note: This blog post was originally published under my old domain(codesmiles.com), <a href=\"http:\/\/codesmiles.com\/post\/asp-net-4-new-feature-html-encode-shorthand.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. <a href=\"https:\/\/web.archive.org\/web\/2010*\/http:\/\/www.codehappiness.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Web Archive link<\/a>.<\/span><br \/>\nSo far if we need to HTML encode content that we throw out to the response stream we will use Server.HtmlEncode() method as below.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: c-sharp;\">\r\n<div id=\"ProdDesc\">\r\n&lt;%= Server.HtmlEncode(\u201cContent\u201d) %&gt;\r\n<\/div><\/pre>\n<p>&nbsp;<\/p>\n<p>Now in ASP.NET 4 we have a new code syntax, which comes handy whenever you want to emit content with HTML encoding, the new syntax is &lt;%: \u2026 %&gt; the \u201c=\u201d character is replaced in this new syntax by the \u201c:\u201d character, as shown below.<\/p>\n<pre class=\"brush: c-sharp;\">\r\n<div id=\"ProdDesc\">\r\n&lt;%: \u201cContent\u201d %&gt;\r\n<\/div><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. So far if we need to HTML encode content that we throw out to the response stream we will use Server.HtmlEncode() method as below. &nbsp; &lt;%= Server.HtmlEncode(\u201cContent\u201d) %&gt; &nbsp; Now in ASP.NET 4 we have<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[17],"_links":{"self":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/159"}],"collection":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":3,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":299,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/159\/revisions\/299"}],"wp:attachment":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}