我可以使用存储到包含文件的脚本(例如test.inc)到WebForm.aspx中吗? 如果答案是肯定我是怎么做的,否则我会向我提出一个替代方法:
//----- Footer.inc ------
Copyright <% DateTime.Now.Year %> , My Company Name .
---------------
// ----- Default.aspx ----
<td class="ColRightStyle" colspan="2">
<% Response.WriteFile("Includes/Footer.inc"); %>
</td>
但是浏览器的结果是:
版权所有&lt;%DateTime.Now.Year%&gt; ,我的公司名称。
(右=&gt;版权所有2014,我的公司名称。)
我花时间搜索相关问题,但我没有找到这样的问题和答案 tnx如此糊涂
答案 0 :(得分:1)
我不知道你为什么这样做,你可以阅读文件内容并解析它,但它仍然不会给你你想要的东西。
例如:<% DateTime.Now.Year %>
应为<%= DateTime.Now.Year %>
以获取您想要的值,这不符合php inc文件。
但是,如果您想这样做,可以使用Custom Expression Builders
Here is an article that covers the subject
BTW,如果你想阅读内容,试试这个:
System.IO.File.ReadAllText(Server.MapPath("~/Include/Footer.inc"))
答案 1 :(得分:1)
您可以使用此:
<td class="ColRightStyle" colspan="2">
<% Response.WriteFile("Includes/Footer.inc"); %>
</td>
并在Footer.inc文件中:
<div class="FooterStyle" dir="rtl" >
Copyright , Notice ©
<br /></div>
<div class="FooterStyle" dir="ltr" >
© Copyright by www.Google.com ; 2004 - <% =DateTime.Now.Year %>
</div>