如何将元标记添加到ASP.NET中的内容占位符页面? [英] How to add meta tag to a content place holder page in ASP.NET?

查看:79
本文介绍了如何将元标记添加到ASP.NET中的内容占位符页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将元标记添加到asp.net中的内容占位符页面?



我想在IE 11浏览器中渲染时强制IE模式为7。能够通过在head标签下放置一个单独的aspx页面来实现。但我想为单个内容占位符页面这样做。



< pre lang =HTML>& lt; meta http-equiv =& ;英寸×UA兼容&安培; QUOT;含量=&安培; QUOT; IE = 7和; QUOT; /& gt;< / pre>



我尝试过:



能够通过在单独的aspx页面的head标签下进行。但我想为单个内容占位符页面这样做。



< pre lang =HTML>& lt; meta http-equiv =& ;英寸×UA兼容&安培; QUOT;含量=&安培; QUOT; IE = 7和; QUOT; /& gt;< / pre>

How to add meta tag to a content place holder page in asp.net?

I want to force IE mode to 7 while rendering in IE 11 browser. Able to do so by putting under the head tag for a separate aspx page. But I want to do so for a single content place holder page.

<pre lang="HTML">&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=7&quot; /&gt;</pre>

What I have tried:

Able to do so by putting under the head tag for a separate aspx page. But I want to do so for a single content place holder page.

<pre lang="HTML">&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=7&quot; /&gt;</pre>

推荐答案

如果要从内容页面向页眉添加自定义标签,只需添加另一个 ContentPlaceholder 位置正确:



母版页:

If you want to add custom tags to the page header from a content page, you just need to add another ContentPlaceholder in the correct position:

Master page:
<%@ Master Language="C#" %>
<!doctype html>
<html>
<head runat="server">
    ...
    <asp:ContentPlaceholder id="HeaderContent" runat="server" />
    ...
</head>
<body>
    ...
    <asp:ContentPlaceholder id="MainContent" runat="server" />
    ...
</body>
</html>



内容页面:


Content page:

<%@ Page Language="C#" MasterPageFile="~/YourMasterPage.master" %>

<asp:Content runat="server" ContentPlaceholderID="HeaderContent">
    Extra headers here...
</asp:Content>

<asp:Content runat="server" ContentPlaceholderID="MainContent">
    Page content here...
</asp:Content>





然而,在这种情况下没有必要这样做。任何< meta http-equiv ... 标记都是响应标头的替代。您真正需要做的就是从内容页面的代码隐藏中添加标题:



However, there's no need to do that in this case. Any <meta http-equiv... tag is a substitute for a response header. All you really need to do is add the header from the code-behind of your content page:

public partial class YourPage : Page
{
    public void Page_Load(object sender, EventArgs e)
    {
        Response.AppendHeader("X-UA-Compatible", "IE=7");
    }
}


这篇关于如何将元标记添加到ASP.NET中的内容占位符页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆