c# - 用户登录后登录 View 未更新?

标签 c# asp.net

我的 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/

相关文章:

c# - 为什么在三元运算符中分配 null 失败 : no implicit conversion between null and int?

asp.net - 保护 http header

C# 如何显示平台目标

c# - 如何拒绝通过浏览器访问目录内容(IIS 服务站点)

javascript - chrome 处理未定义的方式不同吗?

c# - HttpContext.Current.Request.ApplicationPath 在生产环境中为空

.net - 使用 .net 创建 JSON

c# - 将数据发布到 asp.net 网页时出现问题(Desktop C# 端的问题)

c# - Windows 窗体应用程序没有响应

c# - Asp.Net:用户控件、javascript 和 javascript 库