コード例 #1
0
        /// <summary>
        /// Process this request by evaluating it appropriately.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">EventArgs passed in.</param>
        private void Application_ProcessRequest(Object source, EventArgs e)
        {
            // Cast the source as an HttpApplication instance.
            HttpApplication Context = source as HttpApplication;

            if (Context != null)
            {
                // Retrieve the settings from application state.
                Settings Settings = (Settings)Context.Application["Settings"];

                // Call the BeforeEvaluateRequest event and check if a subscriber indicated to cancel the
                // evaluation of the current request.
                EvaluateRequestEventArgs Args = new EvaluateRequestEventArgs(Context, Settings);
                OnBeforeEvaluateRequest(Args);

                if (!Args.CancelEvaluation)
                {
                    // Evaluate the response against the settings.
                    SecurityType Secure = RequestEvaluator.Evaluate(Context.Request, Settings, false);

                    // Take appropriate action.
                    if (Secure == SecurityType.Secure)
                    {
                        SslHelper.RequestSecurePage(Settings);
                    }
                    else if (Secure == SecurityType.Insecure)
                    {
                        SslHelper.RequestUnsecurePage(Settings);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Process this request by evaluating it appropriately.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">EventArgs passed in.</param>
        private void Application_ProcessRequest(Object source, EventArgs e)
        {
            // Cast the source as an HttpApplication instance.
            HttpApplication Context = source as HttpApplication;

            DebugHelper.OutputIf(Context == null, "No context to process!");
            if (Context != null)
            {
                // Retrieve the settings from application state.
                Settings Settings = (Settings)Context.Application["Settings"];
                DebugHelper.Output(Settings != null ? "Settings retrieved from application cache." : "Settings not found in application cache!");

                // Call the BeforeEvaluateRequest event and check if a subscriber indicated to cancel the
                // evaluation of the current request.
                EvaluateRequestEventArgs Args = new EvaluateRequestEventArgs(Context, Settings);
                DebugHelper.Output("BeforeEvaluateRequest event about to fire.");
                OnBeforeEvaluateRequest(Args);
                DebugHelper.Output("BeforeEvaluateRequest event fired and returned.");

                DebugHelper.OutputIf(Args.CancelEvaluation, "Evaluation was canceled by a user event handler.");
                if (!Args.CancelEvaluation)
                {
                    // Evaluate the response against the settings.
                    SecurityType Secure = RequestEvaluator.Evaluate(Context.Request, Settings, false);

                    // Take appropriate action.
                    DebugHelper.OutputIf(Secure == SecurityType.Ignore, "Ignoring request.");
                    if (Secure == SecurityType.Secure)
                    {
                        SslHelper.RequestSecurePage(Settings);
                    }
                    else if (Secure == SecurityType.Insecure)
                    {
                        SslHelper.RequestUnsecurePage(Settings);
                    }
                }
            }
        }