Copied to clipboard

Flag this post as spam?

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


  • David Conlisk 432 posts 1008 karma points
    Sep 19, 2013 @ 18:41
    David Conlisk
    0

    override login page url for protected content

    Hi all,

    In my infinite wisdom, I've decided to implement the mobile version of a site using a mobile template called "m". All mobile requests are thus the same as the desktop site, but with /m appended to it. (I'm doing some mobile device detection, etc, but thats not really relevant to the problem at hand).

    I have protected content on the site. In Umbraco, the content manager chooses the login page to use for unauthenticated users, e.g. /login. I need to be able to override the url that unauthenticated users are bounced to, say from /login/ to /login/m/. However, I'm at a loss as to where I can do this. I already have a custom membership provider on the site that works nicely, but I can't see any methods in there that would help.

    Any ideas? Hopefully I've been clear in describing the issue.

    Thanks!

    David

  • David Conlisk 432 posts 1008 karma points
    Sep 20, 2013 @ 10:32
    David Conlisk
    0

    It might help to mention I'm running Umbraco v4.11.8, non-MVC. Thanks!

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Sep 20, 2013 @ 11:03
    Tim
    100

    You could maybe add some code to the login template to redirect to login/m if the user is on a mobile device?

    It is actually possible to override the template on the master page if you want (rather than redirect to /m). If you hook into the oninit function of the default.aspx page you can override the template. If you put the following code on the default.aspx file of your Umbraco site you'll be sorted.

    You could probably tidy this up to make it more efficient, but you should get the idea!

    :)

    <script runat="server">
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
    
            string pageId = string.Empty;
    
            if (HttpContext.Current.Items["pageID"] != null)
            {
            pageId = HttpContext.Current.Items["pageID"].ToString();
            }
    
            bool isMobile = YOUR MOBILE DETECTION HERE;
    
            if (pageId == "YOUR LOGIN PAGE ID HERE" && isMobile == true)
            {
            this.MasterPageFile = "/masterpages/YOUR MASTER PAGE HERE");
            }
        }
    </script>
    
  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Sep 20, 2013 @ 11:13
    Jon R. Humphrey
    0

    David, These links might help you:

    Umbraco Config Files

    URL Rewrite issue

    Add a Url Rewrite rule

    I've just had to set up over 50 rules for a site I migrated; I didn't use the internal config but went with the IIS UrlRewriter plugin and set up a linked config with them all in there.

    Using the URL Rewrite Module

    Creating Rewrite Rules for the URL Rewrite Module

    IIS7 urlrewrite module - Rules in external xml file

  • David Conlisk 432 posts 1008 karma points
    Sep 20, 2013 @ 11:31
    David Conlisk
    0

    Aw man that is fantastic! Thanks Tim. A very elegant solution to many of the problems I've had, just wish I'd known about this a week ago :) Now to rip out some http handlers...!

  • David Conlisk 432 posts 1008 karma points
    Sep 20, 2013 @ 11:32
    David Conlisk
    0

    Hi Jon,

    Thanks for that, I'd tried using url rewriting as well, but I think Tim has nailed a very elegant solution here.

    Cheers,

    David

  • David Conlisk 432 posts 1008 karma points
    Sep 20, 2013 @ 14:28
    David Conlisk
    0

    Hi all,

    Tim's solution works perfectly in every situation except one. For some reason, on my staging server, I get the IIS standard 404 page for the mobile site. It works fine on my local machine (doesn't it always?) I've checked:

    • umbracoSettings.config
    • 404handlers.config
    • web.config
    • ID of page being requested

    And it all looks fine, same as my local version. But for some reason when changing the master template in code for mobile 404 page, it ends up serving the IIS default 404 page instead.

    Any ideas on what to check?

    Thanks,

    David

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Sep 20, 2013 @ 14:37
    Tim
    1

    In umbracoSettings.config is there a "tryskipiiserrors" setting (can't remember when this was introduced)? If there is, set that to true (you'll need to kick the app pool afterwards I think).

    If that's not there, you need to add to the system.webserver part of the web.config.

    :)

  • David Conlisk 432 posts 1008 karma points
    Sep 20, 2013 @ 15:16
    David Conlisk
    0

    Brilliant, thanks Tim. Beers definitely on me next time I see you. Bit weird that I didn't need to do that on my machine but I'm not complaining. All in all a very neat solution, hell of a lot better than I had yesterday, and much easier to maintain as well. #h5yr

Please Sign in or register to post replies

Write your reply to:

Draft