1-888-365-2779
+1-888-365-2779
Try Now
More in this section

URL Rewriting

7 posts, 0 answered
  1. Zack
    Zack avatar
    41 posts
    Registered:
    18 Apr 2007
    19 May 2009
    Link to this post
    When we first started using Sitefinity (v. 3.0) we wrote an HTTP module that would allow us to "override" the CMS and display a specific ASPX page that we included/built in the project.  The scenario is that we override all CMS content and display that "Down for Maintenance" ASPX page that we included in the project whenever our product database (separate from the Sitefinity CMS database) is going to be unavailable.

    Previously, the way we accomplished this was to call HttpApplication.Context.RewritePath in the event handler that we wired up for the BeginRequest event of our HTTPModule.  We were sure to place the configuration for this custom HTTPModule AFTER the Sitefinity CMS HTTPModule in the web.config file to make sure that our Rewrite took precedence.  This all worked well until we upgraded to Sitefinity 3.6.  Were there any changes to the CMS engine in that version that would cause my custom HTTPModule to stop working?  And if so, is there anything in particular I need to do to get this functionality working again?

    Thanks,

    Zack

  2. Zack
    Zack avatar
    41 posts
    Registered:
    18 Apr 2007
    19 May 2009
    Link to this post
    One item I forgot to mention ... my HTTPModule DOES function as expected when I browse to the /Sitefinity folder within my site, but DOES NOT work correctly when I browse to any other page within the site.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    22 May 2009
    Link to this post
    Hello Zack,

    Thank you for using our services.

    I cannot tell you for sure why your code has stopped working. Yes, there are some improvements that we have made in the source, also the architecture for 3.6 is different. If possible send us the code for your HttpModule.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. Zack
    Zack avatar
    41 posts
    Registered:
    18 Apr 2007
    22 May 2009
    Link to this post
    Ivan,

    As always thank you for the quick response.  I really do appreciate how helpful you folks at Sitefinity are about responding to questions / issues. Might take a few replies back and forth sometimes but we always seem to arrive at the answer we need.

    As for the HTTP Module code, here it is (nothing spectacular, really):

    namespace MyCode.Web.Modules
    {
        public class AppOfflineRewriter : IHttpModule
        {
            public virtual void Init(HttpApplication context)
            {
                context.BeginRequest += new EventHandler(Application_BeginRequest);
            }

            private void Application_BeginRequest(object sender, EventArgs e)
            {

                HttpApplication app = (HttpApplication)sender;
                // Do we need to go offline?
                bool takeAppOffline = StatusChecker.ShouldAppBeOffline();
                if (takeAppOffline &&
                   app.Context.Request.Path != "/Maintenance/AppOffline503.aspx" &&
                   app.Request.Path.ToUpper().EndsWith(".ASPX"))
                {
                    app.Context.RewritePath("~/Maintenance/AppOffline503.aspx", false);
                }
            }

            public void Dispose()
            {

            }
        }
    }

    (just a quick reminder that in our implementation the "AppOffline503.aspx" page is an ACTUAL file in the project, NOT a virtual page in Sitefinity)

    As I mentioned, this code worked for us prior to 3.6.  

    Thanks so much for your help with this ... I'd appreciate any suggestions you might have as to how I could modify this code to achieve the same functionality with 3.6.

    Thanks,

    Zack
  5. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    25 May 2009
    Link to this post
    Hello Zack,

    Thank you for the additional information.
    Yes, seems the improvements we did in the CmsHttpModule are causing this problem in your HttpModule. In the new implementation, we are doing the real redirect a bit latter, so even you rewrite the path, it is rewritten by our CmsHttpModule.

    Here is the updated implementation:
    namespace MyCode.Web.Modules 
        public class AppOfflineRewriter : IHttpModule 
        { 
            public virtual void Init(HttpApplication context) 
            { 
                context.BeginRequest += new EventHandler(Application_BeginRequest); 
            } 
     
            private void Application_BeginRequest(object sender, EventArgs e) 
            { 
     
                HttpApplication app = (HttpApplication)sender; 
                // Do we need to go offline? 
                bool takeAppOffline = StatusChecker.ShouldAppBeOffline(); 
                if (takeAppOffline && 
                   app.Context.Request.Path != "/Maintenance/AppOffline503.aspx" && 
                   app.Request.Path.ToUpper().EndsWith(".ASPX")) 
                { 
                    Telerik.Cms.Web.CmsUrlContext.Current = null
                    Telerik.Cms.Web.CmsHttpRequest.Current.Initialize("~/Maintenance/AppOffline503.aspx"); 
                } 
            } 
     
            public void Dispose() 
            { 
     
            } 
        } 


    Sorry for the inconvenience

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    25 May 2009
    Link to this post
    Hello Zack,

    Thank you for the additional information.
    Yes, seems the improvements we did in the CmsHttpModule are causing this problem in your HttpModule. Actually we are doing the real redirect a bit latter, so even you rewrite the path, it is rewritten by our CmsHttpModule.
    Here is the updated implementation:
    namespace MyCode.Web.Modules 
        public class AppOfflineRewriter : IHttpModule 
        { 
            public virtual void Init(HttpApplication context) 
            { 
                context.BeginRequest += new EventHandler(Application_BeginRequest); 
            } 
     
            private void Application_BeginRequest(object sender, EventArgs e) 
            { 
     
                HttpApplication app = (HttpApplication)sender; 
                // Do we need to go offline? 
                bool takeAppOffline = StatusChecker.ShouldAppBeOffline(); 
                if (takeAppOffline && 
                   app.Context.Request.Path != "/Maintenance/AppOffline503.aspx" && 
                   app.Request.Path.ToUpper().EndsWith(".ASPX")) 
                { 
                    Telerik.Cms.Web.CmsUrlContext.Current = null
                    Telerik.Cms.Web.CmsHttpRequest.Current.Initialize("~/Maintenance/AppOffline503.aspx"); 
                } 
            } 
     
            public void Dispose() 
            { 
     
            } 
        } 

    We are sorry for the inconvenience.

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Zack
    Zack avatar
    41 posts
    Registered:
    18 Apr 2007
    26 May 2009
    Link to this post
    Thank you for the excellent support, as always!

    Zack
Register for webinar
7 posts, 0 answered