HTTP Module and ajax
If I add an HTTP module in the web.config file like this:
<httpModules>
<add name="TheName" type="MyModule"/>
</httpModules>
Will it fire its code if I write this:
public void Init(HttpApplication TheApp)
{
TheApp.BeginRequest += new EventHandler(MyCode);
}
When I'm calling a static page method from jquery like this:
$.ajax({
type: "POST",
url: "../Pages/AnyPage.aspx/AnyPageMethod",
..开发者_开发知识库....
If that's not the proper way to fire MyCode when an ajax request comes in then please let me know what the correct way to do it might look like.
Thanks.
This is one way of firing code when you recieve a request. But its inefficient it will fire on every request No matter what.
It would be more efficient if you wrote a httphanlder that can filter out requests for a specific resource then it will only fire when you request certain file types.
http://support.microsoft.com/kb/307985#2b
Your example is correct although BeginRequest may not be the best fit. You may want to look at all events that can be hooked in to from the HttpModule and then decide which one fits your requirements.
Here is a link to events in ASP.NET 2.0 :
精彩评论