0

重定向“响应在此上下文中不可用”时出错

<%@ Application Language="C#" %>
<script RunAt="server">

void Application_Start(object sender, EventArgs e)
{
    System.Web.HttpContext.Current.Response.Headers.Remove("Server");
}

void Application_End(object sender, EventArgs e)
{
    //  Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)
{
    // Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{
    // Code that runs when a new session is started

}

void Session_End(object sender, EventArgs e)
{
    // Code that runs when a session ends. 
    // Note: The Session_End event is raised only when the sessionstate mode
    // is set to InProc in the Web.config file. If session mode is set to StateServer 
    // or SQLServer, the event is not raised.

}

4

1 回答 1

0

尝试将这段代码从以下移动Application_StartApplication_PreSendRequestHeaders甚至Application_EndRequest如下。

protected void Application_PreSendRequestHeaders(object source, EventArgs e)
{
      System.Web.HttpContext.Current.Response.Headers.Remove("Server");
}

或者,

protected void Application_EndRequest()
{
    System.Web.HttpContext.Current.Response.Headers.Remove("Server");
}
于 2019-05-16T06:40:23.437 回答