【发布时间】:2017-12-22 01:58:01
【问题描述】:
我已尝试以下所有方法来删除“X-AspNetMvc-Version”标头,但它仍然出现? (X-AspNetMvc-版本: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;
}
}
}
【问题讨论】:
-
什么是method1?你试过把 application_start 放进去吗?
-
method1 只是我的内部参考,它没有出现在代码中。
-
请附上您完整的
Global.asax.cs源代码。此问题是在本地发生还是在单独的服务器上发生? -
我已将完整的 Global.asax.cs 代码添加到原始问题中。
-
大家有什么想法吗?
标签: c# asp.net-mvc iis-7