Copied to clipboard

Flag this post as spam?

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


  • Evan 344 posts 99 karma points
    Aug 12, 2009 @ 16:54
    Evan
    0

    Redirecting for mobile applications using altTemplate

    I am putting a redirect in my master template to see if the incoming user is using a mobile device, and if so redirect to the altTemplate Mobile.  How can I get this to work correctly?  I need to redirect to page.aspx?altTemplate=mobile, I can get it all to work except appending the page.aspx.  I am using:

    <script runat="server" language="c#">

        public void Page_Load(Object sender, EventArgs e)
        {
            if (Request.Browser["IsMobileDevice"] == "true" )
            {
                Response.Redirect("?alttemplate=mobile");
            }
        }

    </script>

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 12, 2009 @ 17:13
    Dirk De Grave
    1

    Get the current page from the 'ServerVariables' collection using

    Request.ServerVariables("URL"),

    or use

    umbraco.presentation.nodeFactory.Node.GetCurrent().Url

    to get the url of the current page

     

    Hope this helps.

     

    Regards,

    /Dirk

  • Evan 344 posts 99 karma points
    Aug 12, 2009 @ 17:28
    Evan
    0

    That did not seem to work, I used the following and was given an error...

    <script runat="server" language="c#">

        public void Page_Load(Object sender, EventArgs e)
        {
            if (Request.Browser["IsMobileDevice"] == "true" )
            {
                Response.Redirect(Request.ServerVariables("URL")&"?alttemplate=mobile");
            }
        }

    </script>

     

    It is telling me that it is a property being used as a method...

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 12, 2009 @ 17:53
    Dirk De Grave
    100

    Evan, small mistake as c# indexer uses [] instead of (). And you'll have to replace '&' with '+'

     

    Cheers,

    Dirk

  • Evan 344 posts 99 karma points
    Aug 12, 2009 @ 18:00
    Evan
    0

    Ahh, perfect thanks..

     

     

Please Sign in or register to post replies

Write your reply to:

Draft