Esempio n. 1
0
        } // End Sub Init

        private static void RedirectMatchedUserAgents(object sender, System.EventArgs e)
        {
            System.Web.HttpApplication app = sender as System.Web.HttpApplication;

            if (m_bannedUserAgentsRegex != null && app != null && app.Request != null && !string.IsNullOrEmpty(app.Request.UserAgent))
            {
                if (m_bannedUserAgentsRegex.Match(app.Request.UserAgent).Success)
                {
                    // if (m_strRedirectURL == null)
                    // {
                    // var cbAppContextBase = new HttpContextWrapper(app.Context);
                    // string strRedirectURL = System.Web.Mvc.UrlHelper.GenerateContentUrl("~/Ban/UserAgentBanned", cbAppContextBase);

                    // m_strRedirectURL = uh.Action("UserAgentBanned", "Ban");

                    // } // End if (m_strRedirectURL == null)

                    // if (!System.StringComparer.OrdinalIgnoreCase.Equals(m_strRedirectURL, app.Request.Url.LocalPath))
                    // {
                    //     app.Response.Redirect(m_strRedirectURL);
                    // } // End if (!StringComparer.OrdinalIgnoreCase.Equals(m_strRedirectURL, app.Request.Url.LocalPath))

                    app.CompleteRequest();
                } // End if (m_bannedUserAgentsRegex.Match(app.Request.UserAgent).Success)
            }     // End if (_bannedUserAgentsRegex != null && app != null && app.Request != null && !String.IsNullOrEmpty(app.Request.UserAgent))
        }         // End Sub RedirectMatchedUserAgents
        //***************************************************************************
        // Event Handlers
        //
        void httpApp_BeginRequest(object sender, EventArgs e)
        {
            System.Web.HttpApplication httpApp = (System.Web.HttpApplication)sender;

            iDynamicImageControl ctrl = null;

            // Check to see if the incoming HTTP request points at our "imaginary" web page.
            if (httpApp.Request.Path.ToLower().IndexOf(ImageHandlerRequestFilename) != -1)
            {
                ctrl = (iDynamicImageControl)httpApp.Application[ImageNamePrefix + httpApp.Request.QueryString["id"]];
                if (ctrl == null)
                {
                    return;     // 404 will be returned
                }
                else
                {
                    try
                    {
                        System.IO.MemoryStream mStrm = ctrl.RenderImage();
                        mStrm.WriteTo(httpApp.Context.Response.OutputStream);
                        mStrm.Close();

                        httpApp.Context.ClearError();
                        httpApp.Context.Response.ContentType = ctrl.ContentType;
                        httpApp.Response.StatusCode          = 200;
                        httpApp.Application.Remove(ImageNamePrefix + httpApp.Request.QueryString["id"]);
                        httpApp.Response.End();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }
Esempio n. 3
0
        private void OnBeginRequest(object sender, System.EventArgs e)
        {
            string ip = System.Web.HttpContext.Current.Request.UserHostAddress;


            System.Web.HttpApplication app = ((System.Web.HttpApplication)sender);

            if (app == null)
                return;


            System.Web.HttpContext context = app.Context;
            if (context == null)
                return;

            if (context.Request == null)
                return;

            var nvc = context.Request.QueryString;
            if (nvc == null)
                return;

            string culture = nvc["culture"];
            if (string.IsNullOrEmpty(culture))
                culture = "en-US";


            // context.Request.UserLanguages = new string[] { "a", "b" };

            System.Globalization.CultureInfo cult = System.Globalization.CultureInfo.CreateSpecificCulture(culture);
            System.Threading.Thread.CurrentThread.CurrentCulture = cult;
            System.Threading.Thread.CurrentThread.CurrentUICulture = cult;


        }
Esempio n. 4
0
        private void context_BeginRequest(object sender, EventArgs e)
        {
            System.Web.HttpApplication aHttpApplication = (System.Web.HttpApplication)sender;
            System.Web.HttpContext     aHttpContext     = aHttpApplication.Context;

            NHibernateHelper.GetOrCreateCurrentSession(aHttpContext);
        }
Esempio n. 5
0
 private static bool RedirectToCustomUrl(System.Web.HttpApplication app, Content.CustomUrl u, UrlRewriterParts parts)
 {
     if (u.RedirectToUrl.ToLower().StartsWith("http"))
     {
         if (parts.HasQuery)
         {
             app.Response.Redirect(JoinUrlAndQuery(u.RedirectToUrl, parts.Query));
             return(true);
         }
         else
         {
             app.Response.Redirect(u.RedirectToUrl);
             return(true);
         }
     }
     else
     {
         string outputPath = u.RedirectToUrl;
         outputPath = MakeRelativeCustomUrlSafeForApp(outputPath, app.Request.ApplicationPath);
         if (parts.HasQuery)
         {
             app.Context.RewritePath(JoinUrlAndQuery(outputPath, parts.Query), false);
             return(true);
         }
         else
         {
             app.Context.RewritePath(outputPath, false);
             return(true);
         }
     }
 }
Esempio n. 6
0
 public IRequestInfo Initialize(System.Web.HttpApplication application, ILog log)
 {
     _application = application;
     _context     = application == null ? null : application.Context;
     _log         = log;
     return(this);
 }
Esempio n. 7
0
        } // End Sub Init

        private void OnBeginRequest(object sender, System.EventArgs e)
        {
            System.Web.HttpApplication app = ((System.Web.HttpApplication)sender);

            if (app == null)
            {
                return;
            }


            System.Web.HttpContext context = app.Context;
            if (context == null)
            {
                return;
            }


            string appPath = string.Format("{0}://{1}{2}{3}",
                                           context.Request.Url.Scheme,
                                           context.Request.Url.Host,
                                           context.Request.Url.Port == 80
                                          ? string.Empty
                                          : ":" + context.Request.Url.Port,
                                           context.Request.ApplicationPath);

            System.Console.WriteLine(appPath);


            if (CheckInjection(context.Request))
            {
                System.Web.IHttpHandler mh = new InjectionBlockHandler();
                mh.ProcessRequest(context);
                context.ApplicationInstance.CompleteRequest();
            } // End if (CheckInjection(context.Request))
        }     // End Sub OnBeginRequest
Esempio n. 8
0
        /// <summary>
        /// This method is called during the module's BeginRequest event.
        /// </summary>
        /// <param name="requestedRawUrl">The RawUrl being requested (includes path and querystring).</param>
        /// <param name="app">The HttpApplication instance.</param>
        protected override void Rewrite(string requestedPath, System.Web.HttpApplication app)
        {
            // get the configuration rules
            RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules;

            // iterate through each rule...
            for (int i = 0; i < rules.Count; i++)
            {
                // get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
                string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";

                // Create a regex (note that IgnoreCase is set...)
                Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);

                // See if a match is found
                if (re.IsMatch(requestedPath))
                {
                    // match found - do any replacement needed
                    string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo));

                    // Rewrite the URL
                    RewriterUtils.RewriteUrl(app.Context, sendToUrl);
                    break;                              // exit the for loop
                }
            }
        }
Esempio n. 9
0
        private void OnPostMapRequestHandler(object sender, System.EventArgs e)
        {
            System.Web.HttpApplication app = ((System.Web.HttpApplication)sender);

            if (app == null)
                return;


            System.Web.HttpContext context = app.Context;
            if (context == null)
                return;


            var appPath = string.Format("{0}://{1}{2}{3}",
                                      context.Request.Url.Scheme,
                                      context.Request.Url.Host,
                                      context.Request.Url.Port == 80
                                          ? string.Empty
                                          : ":" + context.Request.Url.Port,
                                      context.Request.ApplicationPath);
            System.Console.WriteLine(appPath);


            if (context.Request.Url.AbsolutePath == "/foo.ashx")
            {
                // IHttpHandler myHandler = new MyHandler();
                // context.Handler = myHandler;
                context.Handler = new ErrorTemplateHandler();
            }

        }
Esempio n. 10
0
        public void Init(System.Web.HttpApplication application)
        {
            DebugHelpers.WriteLine("LocalizingModule::Init -- application: {0}", application);

            // Wire up our event handlers into the ASP.NET pipeline.
            application.BeginRequest              += OnBeginRequest;
            application.ReleaseRequestState       += OnReleaseRequestState;
            application.PostRequestHandlerExecute += OnPostRequestHandlerExecute;
        }
Esempio n. 11
0
        /// <summary>
        /// Handles application "PostReleaseRequestState" event.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        protected void Application_PostReleaseRequestState(object sender, System.EventArgs e)
        {
            System.Web.HttpApplication app = sender as System.Web.HttpApplication;

            if (Volga.Services.Streaming.ResponseFilterChain.CanApply(app.Request) && Ifly.Utils.Input.CanApplyFilterChain(app.Request, app.Response))
            {
                app.Response.Filter = new Volga.Services.Streaming.ResponseFilterChain(app.Context, app.Response.Filter);
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Método acionado quando o módulo é inicializado.
 /// </summary>
 /// <param name="context"></param>
 public void Init(System.Web.HttpApplication context)
 {
     context.BeginRequest   += OnBeginRequest;
     context.EndRequest     += OnEndRequest;
     _validateTicketsTimer   = new System.Threading.Timer(ValidateTickets, null, 0, _validateTicketsInterval);
     _closePendingLoginTimer = new System.Threading.Timer(ClosePendingLogin, null, 0, _closePendingLoginInterval);
     _saveOperationsThread   = new System.Threading.Thread(SaveAccessControlOperations);
     _saveOperationsThread.Start();
 }
Esempio n. 13
0
        public virtual void OnError(object sender, System.EventArgs args)
        {
            System.Web.HttpApplication app = (System.Web.HttpApplication)sender;
            System.Exception ex = app.Server.GetLastError();

            LogException(ex);

            // app.Server.ClearError();

        } // End Sub OnError 
Esempio n. 14
0
 private void Check(object sender, EventArgs e, System.Web.HttpApplication application)
 {
     if (e != GlobalHttpApptests._testArgs)
     {
         throw new InvalidOperationException("Invalid EventArgs");
     }
     if (application.GetType() != typeof(Global))
     {
         throw new InvalidOperationException("The 'application' must be Portal.Global");
     }
 }
Esempio n. 15
0
        /// <summary>
        /// To handle the starting of the incoming request
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void Rewrite_BeginRequest(object sender, System.EventArgs args)
        {
            System.Web.HttpApplication Appl = (System.Web.HttpApplication)sender;
            string path = Appl.Request.Path;

            if (path.StartsWith("/Content/"))
            {
                string clip = GetClip(path);
                sendToNewUrl(url, Appl);
            }
        }
Esempio n. 16
0
        public void Init(System.Web.HttpApplication context)
        {
            InfrastructureDependencyRegistrar.RegisterInfrastructure();

            _context = context;
            _context.PreRequestHandlerExecute += PreRequestHandlerExecute;
            _context.BeginRequest             += BeginRequest;
            _context.AuthenticateRequest      += AuthenticateRequest;
            _context.AcquireRequestState      += AcquireRequestState;
            Initialized();
        }
Esempio n. 17
0
        }    // End Sub Dispose

        void System.Web.IHttpModule.Init(System.Web.HttpApplication context)
        {
            if (context == null)
            {
                throw new System.ArgumentNullException("context", "Could not find HttpApplication");
            }


            context.BeginRequest += new System.EventHandler(OnBeginRequest);

            // context.EndRequest += new System.EventHandler(OnEndRequest);
        } // End Sub Init
Esempio n. 18
0
        // http://www.codeguru.com/csharp/.net/net_asp/article.php/c19389/HTTP-Handlers-and-HTTP-Modules-in-ASPNET.htm
        void System.Web.IHttpModule.Init(System.Web.HttpApplication context)
        {
            if (context == null) throw new System.ArgumentNullException("context", "Could not find HttpApplication");
            context.Error += OnError;

            context.BeginRequest += new System.EventHandler(OnBeginRequest);

            // https://stackoverflow.com/questions/1888016/any-way-to-add-httphandler-programatically-in-net
            // is there any way to programatically add an HttpHandler to an ASP.NET website without adding to the web.config?
            // Obviously you probably want to wrap this in some logic to check for things such as verb, requesting url, etc. 
            context.PostMapRequestHandler += new System.EventHandler(OnPostMapRequestHandler);
            
            // throw new NotImplementedException();
        }
Esempio n. 19
0
        private void context_EndRequest(object sender, EventArgs e)
        {
            System.Web.HttpApplication aHttpApplication = (System.Web.HttpApplication)sender;
            System.Web.HttpContext     aHttpContext     = aHttpApplication.Context;

            NHibernate.ISession aNHibernateSession = NHibernateHelper.GetCurrentSession(aHttpContext);

            if (aNHibernateSession != null)
            {
                aNHibernateSession.Flush();
                aNHibernateSession.Close();
            }

            NHibernateHelper.DisposeCurrentSession(aHttpContext);
        }
Esempio n. 20
0
        /// <summary>
        /// This method is called during the module's BeginRequest event.
        /// </summary>
        /// <param name="requestedPath">The RawUrl being requested (includes path and querystring).</param>
        /// <param name="app">The HttpApplication instance.</param>
        protected override void Rewrite(string requestedPath, System.Web.HttpApplication app)
        {
            // log information to the Trace object.
            app.Context.Trace.Write("RewriterModule", "Entering RewriterModule");

            // get the configuration rules
            RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules;

            // iterate through each rule...
            for (int i = 0; i < rules.Count; i++)
            {
                // get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
                //´øÓòÃû 2011.5.18
                //string lookFor = "^" + rules[i].LookFor + "$";
                //ÎÞÓòÃû
                string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";
                // Create a regex (note that IgnoreCase is set...)
                Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
                //app.Context.Response.Write(lookFor);
                //app.Context.Response.Write("<br />");
                // See if a match is found
                if (re.IsMatch(requestedPath))
                {
                    // match found - do any replacement needed
                    string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo));

                    // log rewriting information to the Trace object
                    app.Context.Trace.Write("RewriterModule", "Rewriting URL to " + sendToUrl);

                    // Rewrite the URL
                    RewriterUtils.RewriteUrl(app.Context, sendToUrl);
                    //app.Context.Response.Write(sendToUrl);
                    //app.Context.Response.Write("<br />");
                    break;                              // exit the for loop
                }
            }
            //app.Context.Response.Write(requestedPath);
            //app.Context.Response.End();
            // Log information to the Trace object
            app.Context.Trace.Write("RewriterModule", "Exiting RewriterModule");
        }
Esempio n. 21
0
        protected override void Rewrite(string requestedPath, System.Web.HttpApplication app)
        {
            try
            {
                RewriterRuleCollection rules = RewriterConfiguration.GetConfig(Helper.GetDomain(app.Request.Url.Authority)).Rules;

                for (int counterRule = 0; counterRule < rules.Count; counterRule++)
                {
                    string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[counterRule].LookFor) + "$";

                    Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);

                    if (re.IsMatch(requestedPath))
                    {
                        string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[counterRule].SendTo));
                        RewriterUtils.RewriteUrl(app.Context, sendToUrl);
                        break;
                    }
                }
            }
            catch { }
        }
Esempio n. 22
0
        /// <summary>
        /// This method is called during the module's BeginRequest event.
        /// </summary>
        /// <param name="requestedRawUrl">The RawUrl being requested (includes path and querystring).</param>
        /// <param name="app">The HttpApplication instance.</param>
        protected override void Rewrite(string requestedPath, System.Web.HttpApplication app)
        {
            // log information to the Trace object.
            app.Context.Trace.Write("ModuleRewriter", "Entering ModuleRewriter");

            // get the configuration rules
            var config = RewriterConfiguration.GetConfig();

            //ÅжÏconfigÅäÖÃÐÅÏ¢
            if (config != null && config.Enabled)
            {
                // iterate through each rule...
                foreach (RewriterRule rule in config.Rules)
                {
                    // get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
                    string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rule.LookFor) + "$";

                    // Create a regex (note that IgnoreCase is set...)
                    Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);

                    // See if a match is found
                    if (re.IsMatch(requestedPath))
                    {
                        // match found - do any replacement needed
                        string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rule.SendTo));

                        // log rewriting information to the Trace object
                        app.Context.Trace.Write("ModuleRewriter", "Rewriting URL to " + sendToUrl);

                        // Rewrite the URL
                        RewriterUtils.RewriteUrl(app.Context, sendToUrl);
                        break;          // exit the for loop
                    }
                }
            }

            // Log information to the Trace object
            app.Context.Trace.Write("ModuleRewriter", "Exiting ModuleRewriter");
        }
Esempio n. 23
0
        private bool GetShowOnlyPublished(System.Web.HttpApplication app, string url)
        {
            if (app.Request.QueryString["previewToken"] == null)
            {
                return(true);
            }

            //Remove token from url
            string token = app.Request.QueryString["previewToken"].ToString();

            Core.Services.SecurityService security = new Core.Services.SecurityService();

            User u = security.GetUserByAuthToken(token);

            if (u == null)
            {
                return(true);
            }

            string[] roles = security.GetUserRoles(u);
            return(!roles.Contains(ADM_CMS_group.UserGroupUId) && !roles.Contains(AMD_SEC_group.UserGroupUId));
        }
 void System.Web.IHttpModule.Init(System.Web.HttpApplication application)
 {
 }
 protected virtual new void Init(System.Web.HttpApplication application)
 {
 }
Esempio n. 26
0
 public virtual void Init(System.Web.HttpApplication app)
 {
 }
Esempio n. 27
0
 protected virtual bool GetUserByName(System.Web.HttpApplication app, string username, out string password, out string[] roles)
 {
     throw null;
 }
Esempio n. 28
0
 protected override bool AcceptCredentials(System.Web.HttpApplication app, string authentication)
 {
     throw null;
 }
Esempio n. 29
0
 public virtual void Init(System.Web.HttpApplication context)
 {
 }
Esempio n. 30
0
 protected void DenyAccess(System.Web.HttpApplication app)
 {
 }