void PostAcquireRequestState (object sender, EventArgs e) {
// The PostAcquireRequestState event is raised after the session data has been obtained.
// If the request is for a class that implements System.Web.UI.Page and it is a rest
// method call, the WebServiceData class (that was explained in a previous post) is used
// to call the requested method from the Page. After the method has been called,
// the CompleteRequest method is called, bypassing all pipeline events and executing
// the EndRequest method. This allows MS AJAX to be able to call a method on a page
// instead of having to create a web service to call a method.
HttpApplication app = (HttpApplication) sender;
HttpContext context = app.Context;
if (context == null)
return;
HttpRequest request = context.Request;
string contentType = request.ContentType;
IHttpHandler currentHandler = context.CurrentHandler;
if (currentHandler == null)
return;
#if TARGET_J2EE
if (!(currentHandler is Page) && currentHandler is IServiceProvider) {
pageType = (Type) ((IServiceProvider) currentHandler).GetService (typeof (Type));
if (pageType == null)
return;
}
#endif
Type pageType = currentHandler.GetType ();
if (typeof (Page).IsAssignableFrom (pageType) && !String.IsNullOrEmpty (contentType) && contentType.StartsWith ("application/json", StringComparison.OrdinalIgnoreCase)) {
IHttpHandler h = RestHandler.GetHandler (context, pageType, request.FilePath);
h.ProcessRequest (context);
app.CompleteRequest ();
}
}