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