2011-07-05 5 views
4

인증 된 사용자의 요청이 있는지 확인하고 필요하지 않은 경우 로그인 페이지로 리디렉션하려는 HTTP 모듈을 만들고 있습니다. http 모듈 : 요청을 사용할 수 없습니다.

내가 web.config 파일에서 모듈을 등록 나는 예외 던지고 다음과 같은 코드가 있습니다

public class IsAuthModule : IHttpModule 
{ 
    public void Dispose() { } 

    public void Init(HttpApplication TheApp) 
    { 
     var TheRequest = TheApp.Request; 

    } 
} 

그것은 말한다 예외를 던지는을

"요청이 컨텍스트에서 사용할 수 없습니다"

내가 뭘 잘못하고 있니?

+0

http://stackoverflow.com/questions/2518057/request-is-not-available-in-this-context – rahularyansharma

답변

5

초기화 단계에서 진행중인 요청이 없습니다. 이 좋은 간결한 대답을

public void Init(HttpApplication TheApp) 
{ 
    TheApp.BeginRequest += Application_BeginRequest; 

    // End Request handler 
    //application.EndRequest += Application_EndRequest; 
} 

private void Application_BeginRequest(Object source, EventArgs e) 
{ 
    // do something 
} 
+1

감사합니다 : 당신은 요청의 시작을위한 이벤트를 구독 할 수 있습니다 , 튜토리얼 길이의 설명보다 확실합니다! – frenchie

관련 문제