2011-04-08 61 views
0

回來當我執行一個假的網址即http://localhost:1166/urldoesnotexist,我的HttpModule內我得到response.StatusCode爲200(OK)。我期待它返回404(未找到)。請參考下面無效的HTTPStatus代碼中的HttpModule

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的假網址返回200?

回答

0

什麼是服務器,例如發送的實際狀態代碼如果你使用另一個工具,如提琴手。

很多頁面發送200時,他們應該發送一個404.你可以找到很多通過搜索「頁面未找到」,雖然這些天有更少的數量和更大數量的有用的網頁 404頁(在搜索引擎的一部分的改善,而不是在普通網站的一部分)。

+0

對不起我花了一段時間才能回覆,因爲我是離開。提琴手向我展示了HTTP/1.1 404 Not Found。我的問題爲什麼HTTP模塊響應代碼給了我200無效的網址是什麼? – Spock 2011-04-12 10:17:24