在ASP.NET 4.0站点中设置X-UA兼容的元标记不起作用 [英] Setting X-UA-Compatible meta tag in ASP.NET 4.0 site doesn't work

查看:108
本文介绍了在ASP.NET 4.0站点中设置X-UA兼容的元标记不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,您可以告诉IE8(并且我假设使用更高版本)如何最好地呈现您的页面.

As I understand it you can tell the IE8 (and I assume later versions) how to best render your page.

这很有用,因为该页面可能是针对IE7,怪癖模式或针对IE8标准模式设计的.据我了解,IE8遇到页面时的默认行为是在IE8标准模式下呈现(尽管不确定它如何解释DOCTYPE).使用此默认设置,用户可以通过单击刷新按钮旁边的兼容性视图"按钮来更改呈现模式.

This is useful because the page may have been designed for IE7, quirks mode or to target IE8 standards mode. As I have it, the default behaviour for IE8 when it encounters a page is to render in IE8 standards mode (not sure how it interprets the DOCTYPE though). With this default the user could change the rendering mode by clicking on the "Compatibility View" button next to the refresh button.

这很高兴给用户一些控制权,但是当您知道您的网站只能使用IE7或其他任何方式很好地呈现时,这是不好的.在那种情况下,您不想让用户做出错误的选择,因此网站告诉> = IE8浏览器如何呈现页面的功能非常有用.

This is nice to give the user some control, but bad when you know your site only renders well with IE7 or whatever. In that case you don't want to enable the user to make the wrong choice and that's where the ability for a website to tell the >= IE8 browser how to render the page is very useful.

您只需在head标签内提供X-UA-Compatible元标签.网上有大量的参考文献,介绍了如何执行此操作以及可以使用哪些值.记住要成为第一个.

You simply have to provide the X-UA-Compatible meta tag the within the head tag. There are loads of references on the web how to do this and what values can be used. Remember to make it the first one.

<html xmlns="http://www.w3.org/1999/xhtml">
  <head  id="Head1" runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=7" />

好的,到目前为止,它并不是什么新鲜事物-但是它对我的ASP.NET项目不起作用?我在其他几个我遇到过同样问题的项目中都尝试过.

OK, so it's nothing new so far - however it just doesn't work for my ASP.NET project? I've tried it on a couple of other projects I have and the same problem.

是否可能存在一种情况,因为我使用的是Visual Studio等开发人员工具,因此IE已配置为始终出于调试目的而显示兼容性视图"按钮?我知道在这里抓稻草.

Is there perhaps a scenario where because I'm using developer tools like Visual Studio, etc. that IE has been configured to always show the "Compatibility View" button for debugging purposes? Grasping at straws here I know.

推荐答案

我发现了为什么会这样.

I found out why this is happening.

似乎ASP.NET的主题正在干扰.在查看渲染的输出时,会为主题中的样式表动态插入一个标签(每个标签一个).

It seems that ASP.NET's theming is interfering. When looking at the rendred output there is a dynamically inserted tag for the stylesheet (one for each) from the theme.

ASP.NET主题引擎将这些项目插入X-UA-Compatible元标记之上,从而打破了IE期望将其作为head元素中的第一个标记的想法.

The ASP.NET theming engine inserts these items above the X-UA-Compatible meta tag, thus breaking IE's expectation of having it as the first tag in the head element.

因此是一个ASP.NET站点,该站点在源中具有主题以及以下内容:

So an ASP.NET site that has theming and the following in the source:

<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head  id="Head1" runat="server"> 
    <meta http-equiv="X-UA-Compatible" content="IE=7" />

将被渲染如下:

<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head id="ctl00_Head1"> 
    <link href="App_Themes/White/Default.css" type="text/css" rel="stylesheet" />
    <meta http-equiv="X-UA-Compatible" content="IE=7" />

这似乎是一个错误.我将为其创建一个MS Connect问题.

This seems to be a bit of a bug. I'll create a MS Connect issue for it.

这篇关于在ASP.NET 4.0站点中设置X-UA兼容的元标记不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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