跳过导航链接首页 > 文章 > 博客正文

Login控件自定义登录

更新日期:2024/2/29   所属类别:asp.net教程:   访问次数:410
通过给控件login定义 OnAuthenticate="Login1_Authenticate",来执行自定义的登陆验证
asp:login id="Login1" runat="server" onauthenticate="Login1_Authenticate" orientation="Horizontal" displayrememberme="false"
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            string username = ((Login)sender).UserName; // 取登录名
            string password = ((Login)sender).Password; //取登录密码
            
            if (username == "sl"&password=="1") // 尝试登录
            {
                e.Authenticated = true; //true登录成功,flase失败
                return;
            //    Response.Redirect("~/index.aspx"); 
            }
            
            else {
                return;
                 
                //Response.Redirect(Request.QueryString["returnUrl"]); 
            }
        }