Copied to clipboard

Flag this post as spam?

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


  • firepol 125 posts 173 karma points
    Apr 05, 2012 @ 14:58
    firepol
    0

    after backend login - redirect to a specific section instead of default "content"

    Hi, please refear to this thread about subscribing to the backend login event.

    After successfull login, I wanted to check the loggedin user, check if the user is of type 1 (1=admin, just as example here), and if yes, redirect him to a specific section, e.g. "settings". So I wrote a class as suggested in the thread I mentioned above, as follows:

        public class CustomUsersMembershipProvider : umbraco.providers.UsersMembershipProvider
    {
    public override bool ValidateUser(string username, string password)
    {
    var success = base.ValidateUser(username, password);

    if (success)
    {
    User u = User.GetAllByLoginName(username, false).FirstOrDefault();

    if ((u.UserType.Id == 1))
    {
    //redirect the user to the Custom Section
    string redirect = "http://" + HttpContext.Current.Request.Url.Authority + "/umbraco/umbraco.aspx#settings";

    HttpContext.Current.Response.Redirect(redirect);
    }
    }

    return success;
    }
    }

    But this doesn't work. Asap I login I'm redirected back to the login, so obveiously I'm doing something wrong.

    To give you an idea of the result I'd like to achieve, try to login to umbraco by using this url:

    http://YourUmbraco/umbraco/login.aspx?redir=%2fumbraco%2fumbraco.aspx%23settings

    After you login, instead of arriving, as usual, to the "Content" Section, you will arrive to the "Settings" section. That would be fine for me, but our customer wants the users of a certain type to be automatically redirected to a specific section after login... so ideally this would be done in th code behind...

    I also tried, instead of Response.Redirect, to use:

                    Page page = (Page)HttpContext.Current.CurrentHandler;
    page.ClientScript.RegisterClientScriptBlock(page.GetType(), "redirect", "window.location = 'http://www.google.com'", true);

    But it didn't work (tried also to do a alert('hello world'); instead of window.location... but I didn't get any javascript alert window...

    Any ideas on how to proceed? Would be appreciated...

    cheers --firepol

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 05, 2012 @ 15:24
    Lee Kelleher
    0

    Hi firepol,

    At that point in the code, your user isn't been authenticated in the back-office... they've had their username/password validated, but no cookies have been set (in Umbraco core code) yet.

    With your previous thread, I thought you only wanted to set a Session object/value.

    Another way you could tackle this... if you've got the time & energy to do it, is take a look at the source-code for my unreleased package: BackOffice Power Scripts:

    https://bitbucket.org/vertino/backoffice-power-scripts-for-umbraco/overview

    By disecting the code, you'll find that I use a HttpModule to inject CSS/JavaScript directly into the back-office.  There is also a way to inject user-controls too.

    It might be useful, it might not... but worth exploring.

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft