2012-03-01 3 views
1

MSDN 설명서의 내용 :HttpContext.RemapHandler가 요청을 처리하는 처리기를 변경해야합니까?

HttpContext.RemapHandler 메서드 - 요청에 대한 처리기를 지정할 수 있습니다.

첫 번째 처리기의 조건에 따라 하나의 처리기에서 다른 처리기로 요청 처리를 이동하려고합니다. HttpContext.RemapHandler 메서드는 두 번째 처리기의 인스턴스를 초기화하는 것으로 보이지만 HttpHandler.ProcessRequest 메서드는 호출하지 않습니다. 응답이 비어 있습니다.

HttpContext.RemapHandler 메서드는 새로운 HttpHandler로 처리를 전송하고 HttpHandler.ProcessRequest 메서드를 호출해야한다고 생각합니까? 아니면 다른 방법이나 HttpModule 같은 다른 접근법을 사용해야합니까?

편집 : 나는 HTTPHandlerFactory를 사용해야한다. 지금 솔루션이 멋지게 작동했습니다.

그래서 정확히 HttpContext.RemapHandler가 무엇입니까? 당신이 지정한

답변

6

당신은 HttpContext.RemapHandler를 사용할 수 있지만 경우 다른 HttpHandler 전화 RemapHandler (PostResolveRequestCacheMvcHandler을 등록 예를 들어, ASP.NET MVC) 당신의 IHttpModule 않습니다 화재. 아마도 IHttpHandler.Process이 호출 된 적이없는 것일 수 있습니다. 이 문제의 경우

, 당신은 단순히 다음과 같이 MvcApplication.RegisterRoutes에 무시하는 경로를 정의 할 수 있습니다 :

routes.IgnoreRoute("your_path/{*pathInfo}"); 

을 또한, 비주얼 스튜디오 웹 개발 서버와 IIS6와 함께, RemapHandler이 작동하지 않습니다 기억 . 여기

세션에 액세스 할 수 여전히 활성화되어 있는지의 여부를 통합 파이프 라인에 기초하여, 처리기를 매핑하는 적당한 방법을 선택하는 방법의 예이다 :

public void Init(HttpApplication application) 
{ 
    if (HttpRuntime.UsingIntegratedPipeline) 
    // For IIS 7 and IIS 8 
    application.PostAuthorizeRequest += Application_PostAuthorizeRequest; 
    else 
    // For IIS 6 
    application.PostMapRequestHandler += Application_PostMapRequestHandler; 
} 

private void Application_PostAuthorizeRequest(object sender, EventArgs e) 
{ 
    ((HttpApplication)sender).Context.RemapHandler(_myHandler); 
} 

private void Application_PostMapRequestHandler(object sender, EventArgs e) 
{ 
    ((HttpApplication)sender).Context.Handler = _myHandler; 
} 

HttpHandlerFactory을 사용하여 차이점 이 경우 HttpModule은 ASP.NET IHttpHandler 매핑과 관계없이 IHttpHandler을 사용할시기를 결정할 수 있다는 점에서 다릅니다. MSDN에 대한 추가 정보 : HTTP Handlers and HTTP Modules Overview.

+0

명확한 답변, 특히 mvc 처리기에 대한 부분!. Thnx! –

+0

.NET 2.0 서비스 팩 2를 적용한 경우 RemapHandler가 PostAuthorizeRequest에서 올바르게 작동합니다. –