通过配置向Cassini添加http标头

时间:2010-03-08 17:28:51

标签: asp.net cassini http-headers

我们的asp.net网站目前已部署到IIS7服务器。我们通过配置文件设置一些http标头,例如:

<httpProtocol>
  <customHeaders>
    <remove name="X-UA-Compatible" />
    <add name="X-UA-Compatible" value="IE=EmulateIE7" />
  </customHeaders>
</httpProtocol>

当我在IIS下托管我的个人网页时,这对我自己很有用。我的同事非常倾向于继续使用Cassini来获得开发经验,这意味着我们的自定义标头不会被发送。有没有办法告诉cassini发送这些标题?

我宁愿不必编写自定义模块来添加它,我也不想在我们网站的每个页面上添加标题。

3 个答案:

答案 0 :(得分:4)

也许您可以在Global.asax中添加预编译器指令,这样它只会在DEBUG模式下编译时添加标头:

protected void Application_BeginRequest(object sender, EventArgs e)
{
#if DEBUG
    HttpContext.Current.Response.AddHeader("X-UA-Compatible", "IE=EmulateIE7");
#endif
}

生产RELEASE编译会忽略这一点但继续通过IIS中的web.config设置添加标题。

答案 1 :(得分:2)

答案 2 :(得分:0)

您还可以在母版页中添加元标记(例如Site.Master),Casini将处理:

    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />