开发者

Is there any Reason for a Web Page (aspx) to Implement the IHttpModule?

开发者 https://www.devze.com 2023-03-22 15:48 出处:网络
Is there any scenario s where I would want to Implement IhttpModule ? I want to invoke some code on BeginRequest:

Is there any scenario s where I would want to Implement IhttpModule ?

I want to invoke some code on BeginRequest :

So I did this : 开发者_Python百科

public partial class ServerTransferThings : System.Web.UI.Page , IHttpModule
{
 ....
 public void Init(HttpApplication context)
 {
     context.BeginRequest += lalala;
 }
 void lalala(object sender, EventArgs e)
 {
 }
}

But it doesn't work. I think it's too early stage becuase the beginRequest executes before the Page object creation .

Am I right ?

Is the solution to create a DLL which implements the IHttpModule and then use the events ?


No, that's quite a code smell. Pages are far enough down the pipe you can't access BeginRequest.

If you want an HttpModule, you can create a class in your project and implement them there. You will have to configure them in the web.config.

0

精彩评论

暂无评论...
验证码 换一张
取 消