/// <summary> /// Raises the onbeginrequest event. /// </summary> /// <param name="args">The <see cref="Rendition.BeginRequestEventArgs"/> instance containing the event data.</param> internal void raiseOnBeginRequest( BeginRequestEventArgs args ) { if( BeginRequest != null ) { BeginRequest( this, args ); }; }
/// <summary> /// Primary Http Pipline. /// Begins the v client request. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void BeginRequest( object sender, EventArgs e ) { /* start the site, or wait * until it's finished starting */ waitUntilStartup(); HttpApplication app = (HttpApplication)sender; HttpContext current = HttpContext.Current; /* raise beginrequest events */ BeginRequestEventArgs beginRequestEventArgs = new BeginRequestEventArgs(current, app, e); Site.raiseOnBeginRequest(beginRequestEventArgs); if(beginRequestEventArgs.AbortDefault) { /* if the event handler says stop messin with the pipeline then quit */ return; } string executionFilePath = current.Request.AppRelativeCurrentExecutionFilePath; bool _isVirtualResourcePath = IsVirtualResourcePath( executionFilePath ); bool _isResourceFile = IsResourceFile( executionFilePath ); bool _useRewrite = !_isVirtualResourcePath && !_isResourceFile; string encodings = current.Request.Headers.Get( "Accept-Encoding" ); if(encodings!=null){ encodings.ToLower(); /* compress */ if( encodings != null && _isVirtualResourcePath) { if(executionFilePath.EndsWith(".js") || executionFilePath.EndsWith(".html")) { if(encodings.Contains("gzip")) { current.Response.AppendHeader("Content-Encoding", "gzip"); current.Response.Filter = new GZipStream(current.Response.Filter, CompressionMode.Compress); } else if(encodings.Contains("deflate")) { current.Response.AppendHeader("Content-Encoding", "deflate"); current.Response.Filter = new DeflateStream(current.Response.Filter, CompressionMode.Compress); } } } } bool _JSONResponse = false; /* response filters - but only if there's response filters */ if(_useRewrite && Main.Site.Redirectors != null) { if(Main.Site.Redirectors.List.FindAll(delegate(Commerce.Redirector rdr) { return rdr.RedirectorType == RedirectorTypes.ResponseFilter && rdr.Enabled; }).Count > 0) { current.Response.Filter = new RewriteHtml(current.Response.Filter); } } /* AJAX requests */ try { _JSONResponse = processHTTPRequest( app ); } catch( Exception ex ) { /* ignore "Thread was being aborted." messages * caused by Response.End(), Response.Redirect() and Server.Transfer()*/ if(!ex.Message.Contains("Thread was being aborted")){ String.Format("BeginRequest Exception =>{0}", ex.Message).Debug(0); } } }