I have a usercontrol on a page that has a login control in it. This controls the display of another user control (if the user is not logged in they get the login control user control). I have some authentication code (see below) that runs when the user clicks the ‘Login’ button. Basically I want it to post back to the same page so they will be logged in and able to now see the other protected user control. This code is not working. Perhaps there is something going on in another page that is making this not work, but does this code itself seem like it should work?
string userName = Membership.GetUserNameByEmail(Login1.UserName);
if (userName != null) { e.Authenticated = Membership.ValidateUser(userName, Login1.Password); } else { e.Authenticated = false; } if (e.Authenticated) { Login1.UserName = userName; ImageButton loginButton = (ImageButton)Login1.FindControl('LoginButton'); if (loginButton != null) { //loginButton.PostBackUrl = Request.Url.ToString(); Response.Redirect(Request.Url.ToString()); } }
The issue is the login control will itself do a redirect setting a cookie or an encrypted authentication ticket in the url (cookieless).
I think the login control has some properties where you can tell it where it will be redirecting to (which overrides the one in the web.config).