我该如何在ASP.NET 5 (MVC6)中使用这些方法?在MVC5中,我在Global.asax中使用它...现在呢?也许是Startup类吗?
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
app?.Context?.Response.Headers.Remove("Server");
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (this.Request.Url.Host.StartsWith("www") || this.Request.Url.IsLoopback) return;
var url = new UriBuilder(this.Request.Url) { Host = "www." + this.Request.Url.Host };
this.Response.RedirectPermanent(url.ToString(), endResponse: true);
}
谢谢!