2013-02-21 2 views
0

다음과 같은 URL이 있습니다 :/employees? employeeId = 3992, ID가 3992 인 직원을 표시합니다. 제대로 작동하고 HTTP 상태 코드는 200입니다. 사람이 같은 URL에 유효하지 않은 ID를 기록하지만StatusCode가있는 IHttpModule RewritePath 404

:/직원 employeeId를 = 39,920, 나는 HTTP 상태 코드 우리의 오류 페이지의 경로를 재 작성하고 보낼 내 HTTP 처리기를 싶습니다 (404)

? 여기에 내가 사용하고 코드는 다음과 같습니다

내가 404에 HTTP 상태 코드를 설정
if (employee == null) 
{ 
    context.RewritePath("/error-page"); 
    context.Response.StatusCode = 404; // if I remove this line, the error-page is displayed, and the StatusCode is 200. 
} 

, 페이지 표시이 표준 ASP.NET 404 오류 페이지를 참조하십시오.

enter image description here

+1

체크 아웃 당신이 http://helephant.com/를 달성하기 위해 노력하고 무엇을 커버하는 것이 게시물을 2009/02/11/improvement-the-way-aspnet-handles-404-requests / – bUKaneer

답변

0

또한 호출

context.Response.TrySkipIisCustomErrors = true; 

예 :

if (employee == null) 
{ 
    context.Response.TrySkipIisCustomErrors = true; 
    context.RewritePath("/error-page"); 
    context.Response.StatusCode = 404; 
}