protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); //Enabled Custom Error Handling MvcHandler.DisableMvcResponseHeader = true; GlobalFilters.Filters.Add(new HandleErrorAttribute()); }
public ActionResult NotFound() { Response.StatusCode = 404; Response.Headers.Add("Custom-Header", "Value"); return View(); }
通过以上三个步骤,即可在ASP.NET MVC中自定义响应头,并将其发送给客户端。