Home > Posts > Gotcha: use server-side comment, not HTML comment in ASP.net

Gotcha: use server-side comment, not HTML comment in ASP.net

I try to remember to use <%– and –%> instead of <!– and –> for comments in server-side web pages, to avoid having implementation details (for security reasons that is) in the output HTML and to keep the download size smaller / have the pages load faster.

What came to me though the other day while making some metadata editing pages for ClipFlair Gallery, was that if you don’t use server-side comments and use classic HTML comments in server-side pages, the code inside the HTML comments is executed at the server side and its output is placed in HTML comments at the web page the client browser downloads.

So this can potentially lead to a very big download and to increased time to generate the page at the sever-side if you accidentally comment out some code block you were using for testing and don’t use server-side comments, but use HTML comments instead to comment it out.

What got me into suspission was the syntax highlighting of Visual Studio 2010. Note below that <%@ Register isn’t highlighted green (as it would be in a server-side comment).

<%@ Page Language="C#" 
         AutoEventWireup="true"
         Title="ClipFlair Activity Gallery"
%>

<!-- THIS IS A BAD USE OF HTML COMMENT MARKER, USE SERVER-SIDE COMMENT INSTEAD

<%@ Register Assembly="CustomXml" Namespace="PAB.WebControls" TagPrefix="cc2" %>

<cc2:CustomXml 
  DocumentUrl="http://gallery.clipflair.net/activity/all.xml"
  XslUrl="http://gallery.clipflair.net/activity/activity.xsl"
  runat="server"
  />

-->

...

Probably JavaEE’s JSP behaves similarly (uses the same symbols for server-side comments), but haven’t tested it.

Categories: Posts Tags: , , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.