X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web.Extensions%2FSystem.Web.Handlers%2FScriptModule.cs;h=bf4bad4bfce183594ff96e3cfc37abf1a5a50c2a;hb=4323fbeaebf249f016dfdd6dc9b3b52a515f87c4;hp=76bb7d55863f091fa22a3a5620c61edc1d696d05;hpb=9887479deb15109062a3ebf0476dd7b2c55113f3;p=mono.git diff --git a/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptModule.cs b/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptModule.cs index 76bb7d55863..bf4bad4bfce 100644 --- a/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptModule.cs +++ b/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptModule.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.Text; using System.Web.UI; +using System.Web.Script.Services; namespace System.Web.Handlers { @@ -43,18 +44,71 @@ namespace System.Web.Handlers } void AuthenticateRequest (object sender, EventArgs e) { + // The AuthenticateRequest event is raised after the identity of the current user has been + // established. The handler for this event sets the SkipAuthorization property of the HttpContext + // for the current request. This property is checked in the authorization module to see + // if it has to omit authorization checking for the requested url. Usually an HttpModule + // use this property to allow anonymous access to some resources (for example, + // the Login Page if we’re using forms authentication). In our scenario, + // the ScriptModule sets the SkipAuthorization to true if the requested url is + // scriptresource.axd or if the authorization module is enabled and the request is a rest + // request to the authorization web service. } 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; + HttpRequest request = context.Request; + string contentType = request.ContentType; + Type pageType = context.CurrentHandler.GetType (); +#if TARGET_J2EE + if (!(context.CurrentHandler is Page) && context.CurrentHandler is IServiceProvider) { + pageType = (Type) ((IServiceProvider) context.CurrentHandler).GetService (typeof (Type)); + if (pageType == null) + return; + } +#endif + 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 (); + } } void PreSendRequestHeaders (object sender, EventArgs e) { HttpApplication app = (HttpApplication) sender; HttpContext context = app.Context; - if (context.Request.Headers ["X-MicrosoftAjax"] == "Delta=true" && context.Response.StatusCode == 302) { - context.Response.StatusCode = 200; - context.Response.ClearContent (); - ScriptManager.WriteCallbackRedirect (context.Response.Output, context.Response.RedirectLocation); + if (context.Request.Headers ["X-MicrosoftAjax"] == "Delta=true") { + Page p = context.CurrentHandler as Page; +#if TARGET_J2EE + if (p == null && context.CurrentHandler is IServiceProvider) + p = (Page) ((IServiceProvider) context.CurrentHandler).GetService (typeof (Page)); +#endif + if (p == null) + return; + ScriptManager sm = ScriptManager.GetCurrent (p); + if (sm == null) + return; + if (context.Response.StatusCode == 302) { + context.Response.StatusCode = 200; + context.Response.ClearContent (); + if (context.Error == null || sm.AllowCustomErrorsRedirect) + ScriptManager.WriteCallbackRedirect (context.Response.Output, context.Response.RedirectLocation); + else + sm.WriteCallbackException (context.Response.Output, context.Error, false); + } + else if (context.Error != null) { + context.Response.StatusCode = 200; + context.Response.ClearContent (); + sm.WriteCallbackException (context.Response.Output, context.Error, true); + } } }