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.
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.
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?
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);
}
}
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.
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:
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
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
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
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
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).
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.
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
is working on a reply...