我的 site.master 设计中有以下登录 View 代码
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ <a href="Log.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
log.aspx.cs 文件具有以下代码:
protected void Page_Load(object sender, EventArgs e)
{
Master.FindControl("CAMenu").Visible = false;
}
protected void btnLogin_Click(object sender, EventArgs e)
{
if (txtUsername.Text == "admin" && txtPassword.Text == "1234")
{
Response.Redirect("NewEvent.aspx");
}
}
但是登录 View 没有更新为欢迎“用户名”..这里有什么错误。我应该改变什么吗???请帮忙
最佳答案
在身份验证事件上使用登录控件:
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
if (txtUsername.Text == "admin" && txtPassword.Text == "1234")
{
e.Authenticated = true;
}
else {
e.Authenticated = false;
}
}
关于c# - 用户登录后登录 View 未更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10226388/