/// <summary>
 /// Raises the <see cref="E:LoadApplicationRules"/> event.
 /// </summary>
 /// <param name="e">The <see cref="ManagedFusion.Rewriter.LoadRulesEventArgs"/> instance containing the event data.</param>
 protected virtual void OnLoadApplicationRules(LoadRulesEventArgs e)
 {
     if (LoadApplicationRules != null)
     {
         LoadApplicationRules(this, e);
     }
 }
        /// <summary>
        /// Handles the Begin event of the request control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void context_BeginRequest(object sender, EventArgs e)
        {
            #region LoadApplicationRules Event

            if (Manager.ApplicationRulesNeedLoading)
            {
                // call load application rules
                var loadRulesArgs = new LoadRulesEventArgs();
                OnLoadApplicationRules(loadRulesArgs);

                Manager.LoadApplicationRules(loadRulesArgs);
            }

            #endregion

            var context      = new HttpContextWrapper(((HttpApplication)sender).Context);
            var rewrittenUrl = Manager.RunRules(context);

            // make sure the rewrittenUrl returned is not null
            // a null value can indicate a proxy request
            if (rewrittenUrl != null)
            {
                // configure IIS7 for worker request
                // this will not do anything if the IIS7 worker request is not found
                Manager.ModifyIIS7WorkerRequest(context);

                // get the path and query for the rewritten URL
                string rewrittenUrlPath = rewrittenUrl.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped);

                // rewrite path using new URL
                if (HttpRuntime.UsingIntegratedPipeline && Manager.Configuration.Rewriter.AllowIis7TransferRequest)
                {
                    var request = context.Request;
                    var headers = new NameValueCollection(context.Request.Headers);

                    int    transferCount       = 1;
                    string transferCountHeader = headers["X-Rewriter-Transfer"];
                    if (!String.IsNullOrEmpty(transferCountHeader) && Int32.TryParse(transferCountHeader, out transferCount))
                    {
                        transferCount++;
                    }

                    headers["X-Rewriter-Transfer"] = transferCount.ToString(CultureInfo.InvariantCulture);

                    context.Server.TransferRequest(
                        rewrittenUrlPath,
                        true,
                        request.HttpMethod,
                        headers
                        );
                }
                else
                {
                    context.RewritePath(rewrittenUrlPath, Manager.Configuration.Rewriter.RebaseClientPath);
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Loads the application rules.
 /// </summary>
 /// <param name="args">The <see cref="ManagedFusion.Rewriter.LoadRulesEventArgs"/> instance containing the event data.</param>
 internal static void LoadApplicationRules(LoadRulesEventArgs args)
 {
     _applicationEngine = new ApplicationEngine(args);
     _applicationEngine.Init();
 }
		/// <summary>
		/// Handles the Begin event of the request control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void context_BeginRequest(object sender, EventArgs e)
		{
			#region LoadApplicationRules Event

			if (Manager.ApplicationRulesNeedLoading)
			{
				// call load application rules
				var loadRulesArgs = new LoadRulesEventArgs();
				OnLoadApplicationRules(loadRulesArgs);

				Manager.LoadApplicationRules(loadRulesArgs);
			}

			#endregion

			var context = new HttpContextWrapper(((HttpApplication)sender).Context);
			var rewrittenUrl = Manager.RunRules(context);

			// make sure the rewrittenUrl returned is not null
			// a null value can indicate a proxy request
			if (rewrittenUrl != null)
			{
				// configure IIS7 for worker request
				// this will not do anything if the IIS7 worker request is not found
				Manager.ModifyIIS7WorkerRequest(context);

				// get the path and query for the rewritten URL
				string rewrittenUrlPath = rewrittenUrl.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped);

				// rewrite path using new URL
				if (HttpRuntime.UsingIntegratedPipeline && Manager.Configuration.Rewriter.AllowIis7TransferRequest)
				{
					var request = context.Request;
					var headers = new NameValueCollection(context.Request.Headers);

					int transferCount = 1;
					string transferCountHeader = headers["X-Rewriter-Transfer"];
					if (!String.IsNullOrEmpty(transferCountHeader) && Int32.TryParse(transferCountHeader, out transferCount))
						transferCount++;

					headers["X-Rewriter-Transfer"] = transferCount.ToString(CultureInfo.InvariantCulture); 

					context.Server.TransferRequest(
						rewrittenUrlPath,
						true,
						request.HttpMethod,
						headers
					);
				}
				else
					context.RewritePath(rewrittenUrlPath, Manager.Configuration.Rewriter.RebaseClientPath);
			}
		}
		/// <summary>
		/// Raises the <see cref="E:LoadApplicationRules"/> event.
		/// </summary>
		/// <param name="e">The <see cref="ManagedFusion.Rewriter.LoadRulesEventArgs"/> instance containing the event data.</param>
		protected virtual void OnLoadApplicationRules(LoadRulesEventArgs e)
		{
			if (LoadApplicationRules != null)
				LoadApplicationRules(this, e);
		}
Пример #6
0
		/// <summary>
		/// Loads the application rules.
		/// </summary>
		/// <param name="args">The <see cref="ManagedFusion.Rewriter.LoadRulesEventArgs"/> instance containing the event data.</param>
		internal static void LoadApplicationRules(LoadRulesEventArgs args)
		{
			_applicationEngine = new ApplicationEngine(args);
			_applicationEngine.Init();
		}