I have a section in an ASP.NET page that has some <% and %> that I do NOT want the ASP.NET compiler to process. How can I specify a section to not be parsed?
+4
A:
You can comment those sections like so:
<%-- (anything to be ignored) --%>
Or if you mean you literally have the <% and %> characters in your page, you should always use <
and >
instead of < and >.
Rex M
2009-07-25 17:56:40
can't do that because they are inside a script. Apparently we are passing <% as a parameter to a flash app or some such.
Yar
2009-07-25 18:05:49
Sorry, I just figured out that somebody left some Ruby code in the ASP.NET site I'm working with. I'm deleting this question now, thanks for your help.
Yar
2009-07-25 18:08:53
Um, but it won't let me delete :)... thanks again. I still would like to know how to tell ASP.NET to ignore a part of the page.
Yar
2009-07-25 18:09:48
A:
Not quite sure what you mean, but you can escape the < and > using their HTML entity equivalents - <
and >
.
Dan Diplo
2009-07-25 17:57:21
+1
A:
There's not a general built-in way to accomplish this. However, if there is no complex logic in the code blocks, you can try the following:
- overload rendering of the page (for example load it in a master page)
- open the .ASPX file and manually read in the text and put it in a StringBuilder
- identify and HTMLEncode the code blocks before inserting into the StringBuilder
- feed the resulting text into Server.Execute() as if dynamically rendering a page or custom control.
Jeff Leonard
2009-07-25 19:07:14
Excellent, thanks for this. The question has turned out to be moot because I was trying to avoid parsing RoR code that was copied and left intact by mistake. I see how the HTMLEncode might work, but the problem is that it (would have been) was script code so it couldn't be rendered as < etc.
Yar
2009-07-25 21:06:01