How to check user role

Discussion in 'C#' started by sbglobal79, Aug 6, 2009.

  1. #1
    Wish for all DP user !

    I have a login template in asp.net Now i want to check if the user is part of the admin role to go the admin/default.aspx if he is part of the users role then go to user/welcome.aspx. How to do this.

    I am using coding as follows:



    protected void Login2_Authenticate1(object sender, AuthenticateEventArgs e)
    {
    if (User.IsInRole("Administrator"))
    {
    Response.Redirect("admin/default.aspx");

    }

    else if (User.IsInRole("free membership"))
    {
    Response.Redirect("user/welcome.aspx");

    }
    }


    Note : i have also tried same coding for Login_LoggedIn events also .

    Thanks is advance all DP user.
     
    sbglobal79, Aug 6, 2009 IP
  2. boomers

    boomers Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I cant see a problem with your code, are you getting an error from the code that you've posted?

    If User.IsInRole("Admin") Then
    'Redirect
    End If
    ^^ Should work fine.
     
    boomers, Aug 6, 2009 IP
  3. sbglobal79

    sbglobal79 Banned

    Messages:
    724
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks for this . But i am using c# . & in C# , I have done this one . but same problem till yet
     
    sbglobal79, Aug 6, 2009 IP
  4. boomers

    boomers Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What is the problem though... what error are you getting?
     
    boomers, Aug 6, 2009 IP
  5. sbglobal79

    sbglobal79 Banned

    Messages:
    724
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    55
    #5

    Dear sir ,

    page is not redirected according to roll after logged in,
     
    sbglobal79, Aug 6, 2009 IP
  6. vihutuo

    vihutuo Well-Known Member

    Messages:
    1,511
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    180
    #6
    try following code

    ASPX
    <asp:Login ID="Login1" runat="server" OnLoggedIn="Login1_LoggedIn">
    PHP:
    CS

      protected void Login1_LoggedIn(object sender, EventArgs e)
        {
            if (Roles.IsUserInRole(Login1.UserName, "admin"))
            {
             Response.Redirect( "~/admin/default.aspx");
            }
            else if (Roles.IsUserInRole(Login1.UserName, "free membership"))
            {
             Response.Redirect("~/user/Welcome.aspx");
            }
            else
            {
              Response.Redirect("~/Error.aspx");
            }
        }
    PHP:
     
    vihutuo, Aug 16, 2009 IP
  7. sbglobal79

    sbglobal79 Banned

    Messages:
    724
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    55
    #7

    Thanks dear !
    But now I am using other method for this task . I will aslo try your suggested method. Thanks for help & giving your coslty time.
     
    sbglobal79, Aug 19, 2009 IP