2012-07-16 74 views
1

我使用VS 2008与IIS6。我想从Http Header“Server”中删除服务器标签。 我在Global.asax中使用了下面的代码。删除HTTP头“服务器”。在IIS 6

void Application_PreSendRequestHeaders(object src, EventArgs e) 
{ 
     HttpContext.Current.Response.Headers.Remove("Server"); 
} 

它显示错误“未设置对象实例的对象引用”。 我怎样才能解决这个

回答

1

这里是为我工作(对于IIS6)的步骤:

  1. 下载并在Web服务器上安装UrlScan 2.5
  2. 打开URLScan配置文件(%WINDIR%\ SYSTEM32 \ INETSRV \ URLScan的\ URLScan.ini中)
  3. 找到将RemoveServerHeader线和的值设置为1(应为将RemoveServerHeader = 1)
  4. 复位IIS和测试,如果报头消失

只是为了记录......如果升级到IIS 7(集成管道模式),您可以通过自定义HttpModule代码实现此目的。

祝你好运!

0

看看这里的答案:https://stackoverflow.com/a/12804722/2074016。它有额外的错误处理,可能会解决您的错误:

protected void Application_PreSendRequestHeaders(object sender, EventArgs e) 
{ 
    // Remove the "Server" HTTP Header from response 
    HttpApplication app = sender as HttpApplication; 
    if (null != app && null != app.Request && !app.Request.IsLocal && 
     null != app.Context && null != app.Context.Response) 
    { 
     NameValueCollection headers = app.Context.Response.Headers; 
     if (null != headers) 
     { 
      headers.Remove("Server"); 
     } 
    } 
} 
+0

这需要IIS管道模式,因为OP问题指出在IIS6中不可用。 – 2013-12-03 15:33:25