5

也许这是一个愚蠢的问题,但我在 Visual Studio 2010 中遇到了这个问题:

在我的母版页中,我有以下代码:

<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>

出于某种奇怪的原因,<%在运行时更改为&lt;%

<%= App.RootPath %>如果放在 head 标签之外的任何地方,则可以正常工作。

有没有人遇到过这种情况并解决了?

更新:

如果我在 head 标签中推迟 runat="server" ,它可以工作。但我需要它。

编辑:

所有这些方法都有效,但问题是缺乏设计师的支持?

4

5 回答 5

5

你的把戏的解释:

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

要找到答案,会产生编译异常。更改App.RootPathApp.RootPaths..,然后导航到源代码(它将显示在错误页面中)。如果编译器匹配类似的东西,<link href='' rel='' >那么它将生成代码来构建相应的HtmlLink实例。所以这就是为什么它解析<%=为文字字符串,然后对其进行编码。

你的把戏欺骗了编译器,这还不错。

我相信它对元标记做同样的事情,(HtmlMeta

于 2011-10-08T09:19:34.233 回答
2

现在,我发现这个解决方法;仍在寻找这种行为的原因。

<link <%= "href=" +App.RootPath +"Css/style.css" %> rel="stylesheet" type="text/css" />
于 2011-10-08T09:07:49.743 回答
2

这也应该有效。

<link href="<%= App.RootPath + "Css/style.css" %>" rel="stylesheet" type="text/css"/>
于 2011-10-08T09:27:50.883 回答
1

我通常使用ResolveUrl

<link href='<%= Page.ResolveUrl("~Css/style.css") %>' rel="stylesheet" type="text/css"/>
于 2011-10-08T23:25:56.957 回答
-1
**problem**
 <link rel="canonical" href="http://www.kayserianadoluhaber.com.tr/haber/<%=kanonikal%>" />

**solved**
 <link rel="canonical" href="http://www.kayserianadoluhaber.com.tr/haber/<%=kanonikal+""%>" />
于 2018-07-15T16:26:42.397 回答