public void Init(System.Web.HttpApplication context)
        {
            rewriteOnlyVirtualUrls = UrlRewriting.Configuration.RewriteOnlyVirtualUrls;
            _contextItemsPrefix    = UrlRewriting.Configuration.ContextItemsPrefix;

            // Copy Settings for easier and faster Accesss during requests
            foreach (RewriteSettings rewriteSettings in UrlRewriting.Configuration.Rewrites)
            {
                RewriteRule rewrite      = null;
                string      providerName = rewriteSettings.Provider;
                if (string.IsNullOrEmpty(providerName))
                {
                    rewrite = UrlRewriting.CreateRewriteRule();
                }
                else
                {
                    rewrite = UrlRewriting.CreateRewriteRule(providerName);
                }
                rewrite.Initialize(rewriteSettings);
                AddRewriteRuleInternal(rewrite);
            }
            context.BeginRequest              += new EventHandler(OnBeginRequest);
            context.PreRequestHandlerExecute  += new EventHandler(OnAppPreRequestHandlerExecute);
            context.PostRequestHandlerExecute += new EventHandler(OnAppPostRequestHandlerExecute);
        }
 internal void ReplaceRewriteRuleInternal(string ruleName, RewriteRule rewriteRule)
 {
     if (rewriteRule.Redirect == RedirectOption.None)
     {
         lockRewrites.AcquireWriterLock(0);
         Rewrites.ReplaceRuleByName(ruleName, rewriteRule);
         lockRewrites.ReleaseWriterLock();
     }
     else
     {
         lockRedirects.AcquireWriterLock(0);
         Redirects.ReplaceRuleByName(ruleName, rewriteRule);
         lockRedirects.ReleaseWriterLock();
     }
 }
 internal void AddRewriteRuleInternal(RewriteRule rewriteRule)
 {
     if (rewriteRule.Redirect == RedirectOption.None)
     {
         lockRewrites.AcquireWriterLock(0);
         Rewrites.Add(rewriteRule);
         lockRewrites.ReleaseWriterLock();
     }
     else
     {
         lockRedirects.AcquireWriterLock(0);
         Redirects.Add(rewriteRule);
         lockRedirects.ReleaseWriterLock();
     }
 }
Example #4
0
 public static void AddRewriteRule(string ruleName, RewriteRule rewriteRule)
 {
     if (rewriteRule == null)
         throw new ArgumentNullException("rewriteRule");
     rewriteRule.Name = ruleName;
     HttpModuleCollection modules = HttpContext.Current.ApplicationInstance.Modules;
     foreach (string moduleName in modules)
     {
         UrlRewriteModule rewriteModule = modules[moduleName] as UrlRewriteModule;
         if (rewriteModule != null)
         {
             rewriteModule.AddRewriteRuleInternal(rewriteRule);
         }
     }
 }
Example #5
0
        public static void ReplaceRewriteRule(string ruleName, RewriteRule rewriteRule)
        {
            if (rewriteRule == null)
            {
                throw new ArgumentNullException("rewriteRule");
            }
            rewriteRule.Name = ruleName;
            HttpModuleCollection modules = System.Web.HttpContext.Current.ApplicationInstance.Modules;

            foreach (string moduleName in modules)
            {
                UrlRewriteModule rewriteModule = modules[moduleName] as UrlRewriteModule;
                if (rewriteModule != null)
                {
                    rewriteModule.ReplaceRewriteRuleInternal(ruleName, rewriteRule);
                }
            }
        }
 internal void ReplaceRewriteRuleInternal(string ruleName, RewriteRule rewriteRule)
 {
     if (rewriteRule.Redirect == RedirectOption.None)
     {
         _lockRewrites.AcquireWriterLock(0);
         Rewrites.ReplaceRuleByName(ruleName, rewriteRule);
         _lockRewrites.ReleaseWriterLock();
     }
     else
     {
         _lockRedirects.AcquireWriterLock(0);
         Redirects.ReplaceRuleByName(ruleName, rewriteRule);
         _lockRedirects.ReleaseWriterLock();
     }
 }
 internal void InsertRewriteRuleBeforeInternal(string positionRuleName, string ruleName, RewriteRule rewriteRule)
 {
     if (rewriteRule.Redirect == RedirectOption.None)
     {
         _lockRewrites.AcquireWriterLock(0);
         Rewrites.InsertRuleBeforeName(positionRuleName, ruleName, rewriteRule);
         _lockRewrites.ReleaseWriterLock();
     }
     else
     {
         _lockRedirects.AcquireWriterLock(0);
         Redirects.InsertRuleBeforeName(positionRuleName, ruleName, rewriteRule);
         _lockRedirects.ReleaseWriterLock();
     }
 }
 internal void AddRewriteRuleInternal(RewriteRule rewriteRule)
 {
     if (rewriteRule.Redirect == RedirectOption.None)
     {
         _lockRewrites.AcquireWriterLock(0);
         Rewrites.Add(rewriteRule);
         _lockRewrites.ReleaseWriterLock();
     }
     else
     {
         _lockRedirects.AcquireWriterLock(0);
         Redirects.Add(rewriteRule);
         _lockRedirects.ReleaseWriterLock();
     }
 }
Example #9
0
        public static void InsertRewriteRule(string positionRuleName, string ruleName, RewriteRule rewriteRule)
        {
            if (rewriteRule == null)
            {
                throw new ArgumentNullException("rewriteRule");
            }
            rewriteRule.Name = ruleName;
            HttpModuleCollection modules = HttpContext.Current.ApplicationInstance.Modules;

            foreach (string moduleName in modules)
            {
                UrlRewriteModule rewriteModule = modules[moduleName] as UrlRewriteModule;
                if (rewriteModule != null)
                {
                    rewriteModule.InsertRewriteRuleBeforeInternal(positionRuleName, ruleName, rewriteRule);
                }
            }
        }
 internal void InsertRewriteRuleBeforeInternal(string positionRuleName, string ruleName, RewriteRule rewriteRule)
 {
     if (rewriteRule.Redirect == RedirectOption.None)
     {
         lockRewrites.AcquireWriterLock(0);
         Rewrites.InsertRuleBeforeName(positionRuleName, ruleName, rewriteRule);
         lockRewrites.ReleaseWriterLock();
     }
     else
     {
         lockRedirects.AcquireWriterLock(0);
         Redirects.InsertRuleBeforeName(positionRuleName, ruleName, rewriteRule);
         lockRedirects.ReleaseWriterLock();
     }
 }
 public static void InsertRewriteRule(string positionRuleName, string ruleName, RewriteRule rewriteRule)
 {
     if (rewriteRule == null)
         throw new ArgumentNullException("rewriteRule");
     rewriteRule.Name = ruleName;
     HttpModuleCollection modules = System.Web.HttpContext.Current.ApplicationInstance.Modules;
     foreach (string moduleName in modules)
     {
         UrlRewriteModule rewriteModule = modules[moduleName] as UrlRewriteModule;
         if (rewriteModule != null)
         {
             rewriteModule.InsertRewriteRuleBeforeInternal( positionRuleName, ruleName, rewriteRule);
         }
     }
 }