Asp.net HttpModule中返回的HttpStatus代码无效

Asp.net HttpModule中返回的HttpStatus代码无效,asp.net,http-headers,httpmodule,Asp.net,Http Headers,Httpmodule,当我执行一个伪url时,即在我的HttpModule中,我得到response.StatusCode作为200(OK)。我希望它返回404(未找到)。请参阅下面的代码 public class HttpPeformanceMonitorModule : IHttpModule { public void Init(HttpApplication context) { context.EndRequest += (sender, e) => Tra

当我执行一个伪url时,即在我的HttpModule中,我得到response.StatusCode作为200(OK)。我希望它返回404(未找到)。请参阅下面的代码

public class HttpPeformanceMonitorModule : IHttpModule
{      
    public void Init(HttpApplication context)
    {
        context.EndRequest += (sender, e) => TraceRequestEnd(sender, "PageLifeCycleTimer", "Begin - End Request");            
    }

    private void TraceRequestEnd(object sender, string timerKey, string title)
    {
        HttpContext httpContext = ((HttpApplication)sender).Context;

        if (response.StatusCode == 200) //for "http://localhost:1166/urldoesnotexist" I get Status Code  200!!!!
        {
             //do stuff...
        }
    } 

}
但是,一旦响应被传递到浏览器中,我在页面上看到的最后一个结果是404页面未找到。-哪个是正确的


有人能解释一下为什么response.StatusCode会为假url返回200吗?

服务器发送的实际状态代码是什么,例如,如果您使用其他工具,如fiddler


很多页面在应该发送404的时候发送了200。你可以通过搜索“未找到的页面”找到很多信息,尽管现在这些页面的数量越来越少,有用页面的数量越来越多,大约404页(这是搜索引擎的一个改进,而不是普通网站的一个改进)。

抱歉,当我不在时,我花了一些时间回复。Fiddler向我显示未找到HTTP/1.1 404。我的问题是,为什么http模块响应代码为无效url提供200?