2012-08-14 2 views

답변

2

당신은 예를 들어 내가 BeginRequest에서 현재 RawUrl 저장 모듈이, 된 ApplicationInstance에서 활성 모듈을 얻을 수 있습니다 :

: 당신의 Web.config에 모듈을 등록해야 물론

public class PlainModule : IHttpModule 
    { 
    private HttpApplication app = null;  
    public string CurrentRequestUrl; 

    public void Init(HttpApplication Context) 
    { 
     this.app = Context; 
     Context.BeginRequest += new System.EventHandler(Begin); 
    } 

    public void Dispose() 
    { 
    } 

    private void Begin(Object Sender, EventArgs e) 
    { 
     this.CurrentRequestUrl = this.app.Request.RawUrl; 
    } 
    } 

<system.web> 
    <httpModules> 
     <add name="PlainModule" type="WebApplication1.PlainModule, WebApplication1"/> 
    </httpModules> 
    </system.web> 

다음 웹 구성에 등록 된 이름을 사용하여 모듈 인스턴스를 가져올 수 있습니다.

protected void Page_Load(object sender, EventArgs e) 
{ 
    PlainModule pm = (PlainModule)HttpContext.Current.ApplicationInstance.Modules["PlainModule"]; 
    Response.Write("Current request URL : " + pm.CurrentRequestUrl); 
}