Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net delimiter <% replaced with &lt;% in head tag?

Maybe its a stupid question, but i'm having this issue in Visual Studio 2010:

in my Master page i've this code:

<head runat="server">

    <title>App Title</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
    <link href="<%= App.RootPath %>Css/style.css" rel="stylesheet" type="text/css" />
</head>

for some strange reason the <% is changed at runtime with &lt;%

<%= App.RootPath %> works normal if put anywhere outside head tag.

Anyone has never experienced this and resolved?

UPDATE:

If i put off runat="server" in head tag, it works. But i need it.

Edit:

All of these methods work, but the problem is lack of designer support?

like image 881
ʞᴉɯ Avatar asked Oct 08 '11 08:10

ʞᴉɯ


1 Answers

The explanation for your trick:

<link <%= "href='" +App.RootPath +"Css/style.css'" %> rel="stylesheet" type="text/css" />

To find the answer generate a compilation exception. Change App.RootPath to App.RootPaths.., then navigate to the source code (it will be shown in the error page). If the compiler matches something like <link href='' rel='' > then it will generate the code to build a corresponding HtmlLink instance. So this is why it parses <%= as a literal string and after that it encodes it.

Your trick cheats the compiler, which is not bad at all.

I believe it does the same thing for meta tags, (HtmlMeta)

like image 78
Adrian Iftode Avatar answered Sep 28 '22 02:09

Adrian Iftode