我有一个使用表单身份验证的网站。出于某种原因,它在第一次运行时工作正常。但在第二次运行时,它表示重定向错误太多了。
登录页面:加载活动
protected void Page_Load(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
Response.Redirect("HomePage.aspx");
}
}
登录页面提交凭据
protected void btnSubmit_Click(object sender, EventArgs e)
{
int recordExistCount = fc.Authenticate(txtUsername.Text.Trim(), txtPassword.Text.Trim());
if (recordExistCount == 1)
{
Session["User"] = "Authenticated";
Session["Username"] = txtUsername.Text.Trim();
fc.IsOnlineRecord(Session["Username"].ToString(),true);
FormsAuthentication.RedirectFromLoginPage(Session["Username"].ToString(), true);
Response.Redirect("HomePage.aspx");
}
else
{
lblStatus.Text = "Username or password specified are incorrect";
lblStatus.BackColor = Color.Yellow;
}
}
主页退出按钮
protected void lbSignOut_Click(object sender, EventArgs e)
{
Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect("LoginPage.aspx");
}
答案 0 :(得分:0)
试试这个
在LoginPage.aspx上
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["action"] != null && Request.QueryString["action"] == "logout")
{
Session.Abandon();
FormsAuthentication.SignOut();
}
else
{
if (HttpContext.Current.User.IsAuthenticated)
{
Response.Redirect("HomePage.aspx");
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
int recordExistCount = fc.Authenticate(txtUsername.Text.Trim(), txtPassword.Text.Trim());
if (recordExistCount == 1)
{
Session["User"] = "Authenticated";
Session["Username"] = txtUsername.Text.Trim();
fc.IsOnlineRecord(Session["Username"].ToString(), true);
FormsAuthentication.RedirectFromLoginPage(Session["Username"].ToString(), true);
}
else
{
lblStatus.Text = "Username or password specified are incorrect";
lblStatus.BackColor = Color.Yellow;
}
}
在MasterPage标记上,放置asp:LoginStatus
这样的
<asp:LoginStatus ID="AdminLoginStatus" runat="server"
LogoutAction="RedirectToLoginPage"
LogoutText="Log Out"
LogoutPageUrl="~/LoginPage.aspx?action=logout"/>