Is there any scenario s where I would want to Implement IhttpModule
?
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
.
精彩评论