LoginView and custom Authenticate ASP.NET WF
I have LoginView in MasterPage, when isn't user logged, application show LoginControl.ascx. In this LoginControl.ascx I make authenticate. Problem is, that, when application authenticate user, then LoginView not change from anonymous template to authenticate template.
protected void btnLogin_clicked(object sender, EventArgs e)
{
// check username and password
if (PlatneJmeno(txtUsernane.Text) && PlatneHeslo(txtPassword.Text))
{
if (Membership.ValidateUser(txtUsernane.Text, txtPassword.Text))
{
//For开发者_开发技巧msAuthentication.RedirectFromLoginPage(txtUsernane.Text, false);
Response.Redirect(Request.RawUrl);
}
else
{
Session["LoginError"] = true;
Session["LoginFromPage"] = Request.RawUrl;
Response.Redirect("login.aspx");
}
}
else
{
Session["LoginError"] = true;
Session["LoginFromPage"] = Request.RawUrl;
Response.Redirect("login.aspx");
}
}
ok, done...
FormsAuthentication.SetAuthCookie(txtUsernane.Text, false);
It appears the problem you are running into is caused by the call to FormsAuthentication.RedirectFromLoginPage being commented out.
That call drops the cookie that tells ASP.NET that the user has been authenticated. Without the cookie ASP.NET will treat future requests as unauthenticated and continue to show the login page.
精彩评论