You must Sign In to post a response.
  • Category: ASP.NET

    How to get role of the user?

    Hi Friends,

    How to get role of the user in Asp.net 4.0?
    when i was excute following code if(User.IsInRole("EDUser")) return error like "object not set" so coundnt root cause of the issue, but this same code is working fine my another appln asp.net 2.0 ...so any one has implemented in 4.0 pls let me know ur thought with implemented source code..

    You people Rock!!!!!

    Thanks & advance
    Ramesh
  • #721012
    Hi,

    Try to check like this


    using System.Web.Security;

    // to get logged user roles
    Roles.GetRolesForUser()

    //if you are not targeting the current logged user.
    Roles.GetRolesForUser(String)

    // if you want to check surrently logged in user for specific role:
    Roles.IsUserInRole("Admin")



    Check the below links to get more info on roles

    http://www.codeproject.com/Articles/342061/Understanding-ASP-NET-Roles-and-Membership-A-Begin

    http://www.asp.net/web-forms/tutorials/security/roles/creating-and-managing-roles-cs



    Thanks,
    Mahesh

  • #721018
    Hi Ramesh M,

    Whenever you try to bind empty data then you got this error "object reference not set to an instance of an object". Please check your data is there or not.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #721027
    Hai Ramesh,
    The issue is that you didnt set the roles using the Site Administration tool and you are checking the role.
    So before checking the user role by using the User.IsInRole("EDUser"), you need to set the security and users for your website.
    You can check in the Solution Explorer, the last icon names as security.
    By clicking on the icon,you will get the Site Administration tool where you can set the permission and user roles.
    After setting from there, now you can use your code which will check the current user with its role to perform the operations.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #721059
    Hi.
    Can you try using :

    if(User.IsInRole(@"DOMAINNAME\EDUser")).

    Thanks

    Reena


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.