Copied to clipboard

Flag this post as spam?

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


  • Teena 44 posts 64 karma points
    Sep 30, 2010 @ 09:59
    Teena
    0

    Adding redirect to Members home at login

    Hi!  We're using the following to generate a login form:

    <umbraco:Item field="bodyText" runat="server"></umbraco:Item>
    <form runat="server">
    <asp:LoginView ID="UmbracoLoginView" runat="server">
        <AnonymousTemplate>
            <asp:Login ID="Login1" runat="server"></asp:Login>
        </AnonymousTemplate>
        <LoggedInTemplate>
            Welcome
            <asp:LoginName ID="LoginName1" runat="server" />
            <asp:LoginStatus ID="LoginStatus1" runat="server" />
        </LoggedInTemplate>
    </asp:LoginView>
    </form>

    Is there an easy way to redirect to the Members home upon successful login? 

    Thanks in advance.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 30, 2010 @ 10:04
    Dirk De Grave
    0

    Sure that's possible Teena, you should register for the LoggedIn event that fires on succesful login and redirect member to its home page.

     

    Cheers,

    /Dirk

  • Teena 44 posts 64 karma points
    Sep 30, 2010 @ 10:42
    Teena
    0

    I'm a stranger in .Net land, you'd have to explain to me in crayon.

    At the url link indicated, I see an example for C# as below:

    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    void SiteSpecificUserLoggingMethod(string UserName)
    {
        // Insert code to record the current date and time
        // when this user was authenticated at the site.
    }
    
    void OnLoggedIn(object sender, EventArgs e)
    {
        SiteSpecificUserLoggingMethod(Login1.UserName);
    }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
        <head runat="server">
        <title>ASP.NET Example</title>
    </head>
    <body>
            <form id="form1" runat="server">
                <asp:Login id="Login1" runat="server" OnLoggedIn="OnLoggedIn"></asp:Login>
    
            </form>
        </body>
    </html>
    

    I can see how this would idicate changing

    <form runat="server">
    <asp:LoginView ID="UmbracoLoginView" runat="server">
       
    <AnonymousTemplate>
           
    <asp:Login ID="Login1" runat="server" OnLoggedIn="OnLoggedIn" ></asp:Login>

    To:

    <form runat="server">
    <asp:LoginView ID="UmbracoLoginView" runat="server">
       
    <AnonymousTemplate>
           
    <asp:Login ID="Login1" runat="server" OnLoggedIn="OnLoggedIn" ></asp:Login>

    But don't know what to do with:

    <script runat="server">
    void SiteSpecificUserLoggingMethod(string UserName)
    {
        // Insert code to record the current date and time
        // when this user was authenticated at the site.
    }
    
    void OnLoggedIn(object sender, EventArgs e)
    {
        SiteSpecificUserLoggingMethod(Login1.UserName);
    }
    </script>
    
    

    So it will redirect to specified location rather than recording date and time.

    Thanks for trying.

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 30, 2010 @ 10:52
    Dirk De Grave
    0

    you'll have to share some info on what exactly you mean with 'redirect to the Members home'? Do you want members to redirect to a specific page? is that page the same page for every member? Or do you have different "home" pages for the members logging on?

    If you have the same page for all members logging in, then you'd need to do the LoggedIn event as you could protect that "home" page (and underlying pages) using the umbraco ui. (Right click on "home" page node, and select 'Public access' which will popup a dialog), and umbraco will handle the authentication process

    On the dialog, choose 'Role based' protection and then choose what member group(s) are allowed to enter this page. Also mark what page you'll be using as the login page (the page you're putting the login control on) and set an error page (which will be used for unauthorized access...)

    If your login control is appearing on every page and would like members to log in from any page, then use the LoggedIn event for redirection using Response.Redirect(umbraco.library.NiceUrl(id));

    Let us know if you need more info.

    Hope this helps.

    Regards,

    /Dirk


  • Teena 44 posts 64 karma points
    Sep 30, 2010 @ 11:30
    Teena
    0

    Yes, we want all members to be redirect to a specific page.

    I created the section and set the Public Access parameters so the members section is protected.  I selected a public page, clientlogin.aspx (page with the login control), as the login page  and set the same page as error page (hoping to add an error message with a url attribute or similar),   I don't see anywhere to set what page the user should be sent to on successful login. Login works and a welcome message is returned on that same page and I could add a link to the members home as below:

    <LoggedInTemplate>
            Welcome
           
    <asp:LoginName ID="LoginName1" runat="server" />
           
    <asp:LoginStatus ID="LoginStatus1" runat="server" />
    <p><a href="/csa-home.aspx">Members Home</a></p>
       
    </LoggedInTemplate>

    But it seems like an auto redirect on successful login is the logical activity, a more elegant solution.

    Thanks, as always for your help.  It's the last day of my Umbraco project and you guys have been great.

  • Teena 44 posts 64 karma points
    Sep 30, 2010 @ 11:37
    Teena
    0

    This is the part I don't follow:

     use the LoggedIn event for redirection using Response.Redirect(umbraco.library.NiceUrl(id));

    Also, there is a link to "Client Login" in the header of my template.  If I figure out the "LoggedIn event", could I use it to display a "Log Out" link there instead for logged in users?

    Athanks in advance.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 30, 2010 @ 11:38
    Dirk De Grave
    0

    you don't need to set the page the member will be redirected to, it's been handled by the login control. If a member browses to the protected section (page and underlying pages), he will be redirected to the login page you've specified, and be redirected to the page he requested upon succesful login.

    However, if you put the asp.net login control on the master template for example (so it becomes available from any page), and the user enters his credentials, he won't be redirected but stay on the same page (well, in fact, he's being redirected to the same page). In that case, you'd need the LoggedIn event to redirect the user to the member's home page (csa-home.aspx)

     

    Hope this helps.

     

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 30, 2010 @ 11:41
    Dirk De Grave
    0

    Ok, let's recap: Are you using a asp.net login control on a master template (available on all pages), or just using the login control on the login page you've specified in the 'Public access' dialog?

     

    /Dirk

  • Teena 44 posts 64 karma points
    Sep 30, 2010 @ 12:07
    Teena
    0

    I am using a asp.net login control on just the login page specified in the 'Public access' dialog.  Thanks to your help,  I do understand now that if I just point the links to "Client Login" at the protected "Members Home" instead of the actual page that has the login control, I don't need to redirect.  Problem solved, thank you very much.

    The remaining complication is the "Client Login" link in the master template.

    In the master template is a simple link for the clients to access login from anywhere on the site:

    <a href="/csa-home.aspx" style="text-align:right; color:white; font-size:.67em;">client
          login</a>

    I would like to alter this to:

    Show if Logged In: <a href="javascript:__doPostBack('ctl00$ctl00$ctl00$ctl00$ContentPlaceHolderDefault$childContent$childContent$UmbracoLoginView$LoginStatus1$ctl00','')" style="text-align:right; color:white; font-size:.67em;">Logout</a>

     

    Show if Not Logged In: <a href="/csa-home.aspx" style="text-align:right; color:white; font-size:.67em;">Client
          Login</a>

    Looking at the syntax in the login form, I tried:

    <asp:LoginView ID="UmbracoLoginView" runat="server">
        <AnonymousTemplate>     
    <a href="/csa-home.aspx" style="text-align:right; color:white; font-size:.67em;">Client
          Login</a>   
        </AnonymousTemplate>
        <LoggedInTemplate>
            <a href="javascript:__doPostBack('ctl00$ctl00$ctl00$ctl00$ContentPlaceHolderDefault$childContent$childContent$UmbracoLoginView$LoginStatus1$ctl00','')" style="text-align:right; color:white; font-size:.67em;">Logout</a>
        </LoggedInTemplate>
    </asp:LoginView>

    The "logout link" javascript url was copied from the "logout link" displayed on the actual login page after successful login.  It does work to display the "Login" link to users who are not logged in and "Logout" to users who are but the logout link does not actually work unless you are on the actual login page.

    Thanks in advance.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 30, 2010 @ 12:12
    Dirk De Grave
    0

    You should use the LoginStatus control instead of the LoginView for that. 

     

    Cheers,

    /Dirk

  • Teena 44 posts 64 karma points
    Sep 30, 2010 @ 16:38
    Teena
    0

    What does that look like?  I tried this:

    <asp:LoginStatus id="LoginStatus1" runat="server"></asp:LoginStatus> 

    xxx

    It returned the form error:

    Control 'ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderDefault_LoginStatus1' of type 'LoginStatus' must be placed inside a form tag with runat=server.

    So I tried this:

    <form runat="server">
    <asp:LoginStatus id="LoginStatus1" runat="server"></asp:LoginStatus>
    </form>

    Which returned this error:

    A page can have only one server-side Form tag.

    If I have the syntax basically right, I will try move the existing form tags to wrap the whole template.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 30, 2010 @ 16:40
    Dirk De Grave
    0

    Yup, that should be the solution, can only have one server side form tag in your asp.net templates.

     

    Cheers,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft