how to test a userrole inside a usercontrol

Last post 10-07-2008 5:45 AM by Ganesh@Nilgris. 4 replies.

Sort Posts:

  • how to test a userrole inside a usercontrol

    10-04-2008, 5:48 AM

    i have a user control which contains a "repeater" and inside "itemtemplate". Inside the itemTemplates i have a panel. Based on the userauthentication i check if the user belongs to a paricular role. if it is true i visible the panel or disable the panel. below code works fine in the codebehind of a page not in the codebehind of user control. below is the code

    protected bool IsPosters;protected void Page_Load(object sender, System.EventArgs e)

    {

    IsPosters = User.IsInRole(
    "Posters");

    panel1.Visible = IsPosters;

    }

    Any ideas???

     

    Jai Ganesh. J , GSD ,India

    Please Mark As Answer If my reply helped you.
  • Re: how to test a userrole inside a usercontrol

    10-04-2008, 6:08 AM
    • Participant
      803 point Participant
    • Mrugank
    • Member since 09-25-2008, 7:19 AM
    • Ahmedabad
    • Posts 161

     HI

    You can create the Seperate Class for the Featching Role as whatever you do

    That Role Should be stored in the session variable 

    Session["Role"]="Role";

    This Will help you to get role everywere

    and you can get the session value in usercontrol

    String strRole=Session["Role"].ToString(); //Or what ever you want this is just example

    and accordingly you can do the operation on panel

     

    Please Mark As Answer if it Helps You

     

    Please Mark As Answer if It Helps

    Regards
    Mrugank Dholakia
  • Re: how to test a userrole inside a usercontrol

    10-04-2008, 6:54 AM

    Mrugank:

     HI

    You can create the Seperate Class for the Featching Role as whatever you do

    That Role Should be stored in the session variable 

    Session["Role"]="Role";

    This Will help you to get role everywere

    and you can get the session value in usercontrol

    String strRole=Session["Role"].ToString(); //Or what ever you want this is just example

    and accordingly you can do the operation on panel

     

    Please Mark As Answer if it Helps You

     

    i would like to "User" method in the usercontrol but not sure how to achieve it

     

    Jai Ganesh. J , GSD ,India

    Please Mark As Answer If my reply helped you.
  • Re: how to test a userrole inside a usercontrol

    10-06-2008, 11:54 PM

    Hi Ganesh,

    This way:

     

        protected void Page_Load(object sender, EventArgs e)
        {
            IPrincipal user = this.Page.User;
            this.Label1.Text  = user.IsInRole("posters").ToString ();
        }
     

    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
  • Re: how to test a userrole inside a usercontrol

    10-07-2008, 5:45 AM

    Samu Zhang - MSFT:

    Hi Ganesh,

    This way:

        protected void Page_Load(object sender, EventArgs e)
        {
            IPrincipal user = this.Page.User;
            this.Label1.Text  = user.IsInRole("posters").ToString ();
        }

     

    yes, that what i was expecting. Thanks for the effort. I need to add the namespace System.Security.Principal to get the interface.

     

    Jai Ganesh. J , GSD ,India

    Please Mark As Answer If my reply helped you.
Page 1 of 1 (5 items)