开发者

how to show failure text if the loggedin user role not found ...?

How to display login failure text if user logging in user role id differ than vendors role ...

i m using the following code to authenticate user role during logging in

Protected Sub Login3_LoggingIn(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles Login3.Lo开发者_如何学编程ggingIn
        Dim user As TextBox = Me.Login3.FindControl("UserName")
        If Roles.IsUserInRole(user.Text, "Vendors") Then
            Login3.DestinationPageUrl = ("~/vendors/select_service.aspx")
        Else
            Login3.DestinationPageUrl = ("~/login.aspx")
        End If
    End Sub


in my opinion, the roles purposes is not the login. login must validate credentials like username or password.

Roles in my opinion should used to determine if user have access or not to a specific section of your website/application.

to show the message, consider to add a label and change the label text property.


In my situation, I wanted to authenticate the users, but if they had no roles associated with their account, cancel the login and display a message. Based on Flavio's suggestion to use a Label, this is what I came up with. (LoginInput is my LoginControl)

Protected Sub LoginInput_LoggingIn(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)

    Dim a As System.Web.UI.WebControls.Login = CType(sender, System.Web.UI.WebControls.Login)

    LoginError.Visible = False

    If (Membership.ValidateUser(a.UserName, a.Password)) Then
        If (Roles.GetRolesForUser(a.UserName).Count = 0) Then
            LoginError.Text = "Your account does not have permission to access the system."
            LoginError.Visible = True
            e.Cancel = True
        End If
    End If

End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜