Copied to clipboard

Flag this post as spam?

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


  • Thomas Kahn 602 posts 506 karma points
    Jan 05, 2010 @ 14:01
    Thomas Kahn
    0

    Member.AddMemberToCache doesn't work for me - any clues why?

    I'm building a login user control and when the user has entered login name and password, this method is executed:

    protected void LoginMember_click(object sender, EventArgs e)
    {
    Member m = Member.GetMemberFromLoginNameAndPassword(tbxEmail.Text, tbxPassword.Text);

    if (m != null)
    {
    //Log member in
    Member.AddMemberToCache(m);

    // Switch to logout panel
    LoginPanel.Visible = false;
    LogoutPanel.Visible = true;
    litLogoutText.Text = "You are now logged in as " + m.Text + ".";

    }
    else
    {
    vldLoginFailed.IsValid = false;
    }

    }

    I have verified that a user is fetched when the correct login name (in this case it's an email address) and password is submitted. But after Member.AddMemberToCache(m) is executed, no member is logged in. This I have verified by trying to get the current member using Member.GetCurrentMember().

    Any ideas where I should start looking for errors?

    I'm using umbraco v 4.0.3 (Assembly version: 1.0.3625.27276) on a Windows 2008 Web Server (IIS 7.0.

    Regards,
    Thomas Kahn

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 05, 2010 @ 14:13
    Dirk De Grave
    1

    thomas, 

    why aren't you using the standard asp.net login controls? It's available oob in umbraco (or even better, available in asp.net) and does all you need; use the login control in combination with the asp loginstatus/loginview control and you're set.

     

    Cheers,

    /Dirk

  • Thomas Kahn 602 posts 506 karma points
    Jan 05, 2010 @ 14:20
    Thomas Kahn
    0

    Hi Dirk,

    Yes, I've understood that building my own control is not recommended. I just looked at these instructions:

    http://umbraco.org/documentation/books/api-cheatsheet/working-with-members

    ...and came to the conclusion that I'd have to build my own control(?) But I guess I was wrong.

    I also found a similar post that explains why my code doesn't work:

    http://our.umbraco.org/forum/developers/api-questions/4207-Member-login-won%27t-work

    The problem occurs when directory URL's are active. Very strange!

    Regards,
    Thomas Kahn

     

  • Thomas Kahn 602 posts 506 karma points
    Jan 05, 2010 @ 14:40
    Thomas Kahn
    0

    Is there a page or tutorial that describes how to work with the ASP.NET standard controls in combination with Umbraco 4? I have only implemented logins and password protected pages for Umbraco 3 before?

    Are these controls put inside user controls or directly in the templates?

    /Thomas K

  • Chad Rosenthal 272 posts 474 karma points
    Jan 05, 2010 @ 15:09
    Chad Rosenthal
    1

    I'll be one of the few advocates that says to not use the .NET controls. You can use all of the functionality of Membership without the controls. The reason why I've switched away was more to do with the HTML code that is added to the page and trying to make it more semantic.

    Here is the code that I use to log in. I turned on directory urls, and it worker (although the actual directory URL's didn't).

                if (Page.IsValid)
                {
                    string username = this.txtUsername.Text;
                    string password = this.txtPassword.Text;
    
                    // Validate the user against the Membership framework user store      
                    if (Membership.ValidateUser(username, password))
                    {
                        // Log the user into the site           
                        FormsAuthentication.Authenticate(username, password);
                        FormsAuthenticationTicket tkt = new FormsAuthenticationTicket(
                            1, 
                            username, 
                            DateTime.Now, 
                            DateTime.Now.AddMinutes(30),
                            true, 
                            string.Empty);
    
                        string cookiestr = FormsAuthentication.Encrypt(tkt);
                        HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
                        ck.Expires = tkt.Expiration;
                        ck.Path = FormsAuthentication.FormsCookiePath;
                        Response.Cookies.Add(ck);
    
                        string redirectUrl = FormsAuthentication.GetRedirectUrl(username, false);
    
                        if (redirectUrl.Length > 0)
                        {
                            Response.Redirect(redirectUrl);
                        }
                        else
                        {
                            Response.Redirect(FormsAuthentication.DefaultUrl);
                        }
                    }
                    else
                    {
                        // If we reach here, the user's credentials were invalid
                        this.ShowMessageBox(this.LoginErrorMessage, Enums.MessageBoxCssClass.Error);
                    }
                }
  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jan 06, 2010 @ 03:50
    Aaron Powell
    0

    There's stuff on the wiki about the standard membership operations - http://our.umbraco.org/wiki/how-tos/membership-providers

    But really just check out any example on using ASP.NET Membership, that's all you need to do.

  • Thomas Kahn 602 posts 506 karma points
    Jan 06, 2010 @ 16:01
    Thomas Kahn
    0

    Chad: That is my experience as well. The ASP.NET standard controls generate markup that's so ugly it makes you blush - tables for layout etc. If you take any kind of pride in your XHTML/CSS-craftsmanship, having an ASP.NET control to the page is like having a big pimple on the nose.

    Slace: Thanks! That was more updated info - just what I needed! After having written my questions I discovered that it was very simple.

    /Thomas

Please Sign in or register to post replies

Write your reply to:

Draft