Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 从http响应头中删除服务器标记_Asp.net_Namespaces_Http Headers_Class Library - Fatal编程技术网

Asp.net 从http响应头中删除服务器标记

Asp.net 从http响应头中删除服务器标记,asp.net,namespaces,http-headers,class-library,Asp.net,Namespaces,Http Headers,Class Library,我正在尝试从asp.net(C#)中的http响应头中删除服务器标记 在堆栈溢出的帮助下,我成功地创建了.dll文件并在我的项目中添加了它的引用,但仍然可以在http头中看到服务器标记。下面是我的.dll文件的代码 using System; using System.Web; namespace ServerHeaders { public class CustomServerHeaderModule : IHttpModule { public void Init(HttpAppli

我正在尝试从asp.net(C#)中的http响应头中删除服务器标记 在堆栈溢出的帮助下,我成功地创建了.dll文件并在我的项目中添加了它的引用,但仍然可以在http头中看到服务器标记。下面是我的.dll文件的代码

using System;
using System.Web;
namespace ServerHeaders
{
public class CustomServerHeaderModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.PreSendRequestHeaders += OnPreSendRequestHeaders;
    }
    public void Dispose() { }
    static void OnPreSendRequestHeaders(object sender, EventArgs e)
    {
        // remove the "Server" Http Header
        HttpContext.Current.Response.Headers.Remove("Server");

    }
}
}
我在网站中添加了对该文件的引用,并在web.config中添加了必需的标记,如下所示

<configuration>
<system.web>
    <compilation debug="true" targetFramework="4.0"/>
<httpRuntime enableVersionHeader="false" />
<httpModules>
  <add name="CustomServerHeaderModule1" type="ServerHeaders.CustomServerHeaderModule" />
</httpModules>
</system.web>

<system.serviceModel>
    <bindings/>
    <client/>
</system.serviceModel>
</configuration>

错误是对象引用未设置为对象的实例。如何解决这个错误?我正在从本地主机(使用F5)运行项目。

您在项目中是否有对
System.Web.dll
的引用?@mellamokb..No。我没有添加任何参考资料。我刚刚导入了一个名称空间“System.web”,是否需要添加引用?如果是,怎么做?@mellamokb。我增加了参考资料。现在一切都好了。但是如何创建类库呢?意味着如何运行和创建dll?看看这是否有帮助。。。
HttpContext.Current.Response.Headers.Remove("Server");