.Net 2.0带的Login控件很好用,用过很多次的,这次却发现了一个问题

因为可以允许用户使用不同的用户名(系统用户名,邮箱,NT帐号等)登录,后台通过用户表都会找到系统用户名

用于设置验证cookie; 但是问题来了,HttpContext.Current.User.Identity.Name的值始终是Login控件中输入的用户名

而不是通过转换后的系统用户名,即使强制设定了 HttpContext.Current.User 的值, 

把e.Authenticated 设为 true后,在验证的函数Login1_Authenticate结束以后,都会自动被改为Login的输入用户名 

没办法,为了得到正确的 HttpContext.Current.User.Identity.Name值,只好如此做

 

 

     protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)

    {
        string pasUserName;
        bool bolR = WSC_Permission.LoginValidateByEntries(Login1.UserName, Login1.Password, out pasUserName);
        if (bolR)
        {
            FormsAuthentication.SetAuthCookie(pasUserName, this.Login1.RememberMeSet);

 

            LogManager.Write(LogActionType.Login,
                            "The user use this account["
                            + this.Login1.UserName + "]  to log on.");

            Server.Transfer("FrameMain.aspx");
        }
        else
            MessageBox.Show(Resources.Resource.MSG_ERR_CHECK_PASSWORD);

        e.Authenticated = false; 
    }

 

 

 

 

 

 

 

 

 

代码不够优美,不知道有没有更好的解决办法

 

posted on 2010-09-17 15:53  YoungSin  阅读(608)  评论(0编辑  收藏  举报