.NET IIS7无法删除X-AspNetMvc-Version标头?

时间:2017-07-17 13:36:36

标签: c# asp.net-mvc iis-7

我已尝试以下所有方法删除'X-AspNetMvc-Version'标题,但它仍然出现? (X-AspNetMvc-Version:5.2)

IIS没有添加任何标头。可能还有其他与标​​题冲突的内容导致它仍然显示?

非常感谢任何帮助。提前谢谢。

的web.config

<httpRuntime requestValidationMode="2.0" enableVersionHeader="false" targetFramework="4.5" maxRequestLength="1048576" />

Global.asax.cs - (尝试1)

MvcHandler.DisableMvcResponseHeader = true; 

Global.asax.cs - (尝试2)

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
    HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
}

Global.asax.cs - (尝试3)

protected void Application_BeginRequest(object sender, EventArgs e)
{
    var application = sender as HttpApplication;
    if (application != null && application.Context != null)
    {
        application.Context.Response.Headers.Remove("X-AspNetMvc-Version");
    }
}

这是完整的Global.asax.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace website
{

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            MvcHandler.DisableMvcResponseHeader = true; 
        }
    }
}

1 个答案:

答案 0 :(得分:2)

发布我的网站时遇到同样的问题。

解决我的问题的唯一方法是在SELECT orderId, SUM(cost) AS cost FROM MyTable GROUP BY orderId

中添加此代码
Global.asax.cs

注意:这会删除protected void Application_BeginRequest(object sender, EventArgs e) { string[] headers = { "Server", "X-AspNetMvc-Version" }; if (!Response.HeadersWritten) { Response.AddOnSendingHeaders((c) => { if (c != null && c.Response != null && c.Response.Headers != null) { foreach (string header in headers) { if (c.Response.Headers[header] != null) { c.Response.Headers.Remove(header); } } } }); } } X-AspNetMvc-Version标题。