Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ferdy Hoefakker 214 posts 248 karma points
    Apr 18, 2011 @ 12:37
    Ferdy Hoefakker
    0

    Switching between templates at runtime

    Hey all, new question from me :D

    I have recently found out, that if I go to www.mydomain.com/template-alias, Umbraco will be awesome and load the entered template alias rather then the one you set in the backend. Now, this seems like great functionality for a mobile version of the website, so I have been playing around with it.

    The thing is, I need to rewrite the url. I kinda want all: mobile.mydomain.com requests to go to mydomain.com/mobile or mobile.mydomain.com/page1 -> mydomain.com/page1/mobile.

    No matter what I try though, it's not accepting the rewrite. I tried both ISAPI and the .netRewriting in Umbraco, but neither is working. Server is windows 2003 and we are using Umbraco 4.5.2

    So I was hoping someone could help with this. Thanks in advance!

    -Ferdy

  • Pasang Tamang 258 posts 458 karma points
    Apr 18, 2011 @ 13:37
    Pasang Tamang
    0

    Hi Ferdy

    You can redirect your page to mobile.mydomain.com by checking useragent. Here is sample code

    <script runat="server">  
        protected void Page_Load(object sender, EventArgs e)
        {
    string strUserAgent = Request.UserAgent.ToLower();
    if(strUserAgent.Contains("iphone"))
    {
    Response.Redirect("mobile.mydomain.com);
    }
    }
    </script>

    Hope this make sense

    Pnima

  • Ferdy Hoefakker 214 posts 248 karma points
    Apr 18, 2011 @ 13:51
    Ferdy Hoefakker
    0

    Pasang, I thank you for your time, but that is not what I asked. I need help with url rewriting, not a simple redirect script.

    Regards,

    -Ferdy

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Apr 18, 2011 @ 14:36
    Darren Ferguson
    3

    Hi Ferdy - can you expand upon "not working" perhaps posting your config -

    Another approach would to be to hook into the BeforeRequestInit event:

    e.g.

     

     public class MobileTemplate : ApplicationBase
        {
            public MobileTemplate()
            {
                UmbracoDefault.BeforeRequestInit += UmbracoDefaultBeforeRequestInit;
            }
            void UmbracoDefaultBeforeRequestInit(object sender, RequestInitEventArgs e)
            {
                if (!HttpContext.Current.Request.UserAgent.ToLower().Contains("iphone")) return;
                var page = (UmbracoDefault)sender;
                page.MasterPageFile = template.GetMasterPageName(e.Page.Template, "mobile");
            }
        }

     

  • Ferdy Hoefakker 214 posts 248 karma points
    Apr 18, 2011 @ 14:42
    Ferdy Hoefakker
    0

    Hi Darren,

    With not working, I meant no matter what I did (even rewrite code that 100% worked on another site) just wouldn't be fired. But we seem to have found the problem already. My collegue has reinstalled the ISAPI rewrite engine and everything seems to be working fine now.

    If it's gonna act up again, I'll post my config, but for now it seems to be unrelated.

    -Ferdy

Please Sign in or register to post replies

Write your reply to:

Draft