Re: Roles not working

From: Hernan de Lahitte (hernan_at_lagash.com)
Date: 11/24/04

  • Next message: James McFarland: "FormsAuthentication Roles Problem"
    Date: Wed, 24 Nov 2004 11:30:25 -0300
    
    

    Change this line:
    Thread.CurrentPrincipal = new GenericPrincipal(Context.User.Identity,
    roles);

    To this:
    Context.User = new GenericPrincipal(Context.User.Identity,
    roles);

    -- 
    Hernan de Lahitte
    http://weblogs.asp.net/hernandl
    "Neils Christoffersen" <NeilsChristoffersen@discussions.microsoft.com> 
    escribió en el mensaje 
    news:8C2A7EC2-7F42-4749-99EB-2431EC85D4DF@microsoft.com...
    >I have a quick question about ASP.NET roles.
    >
    > I have the following in in Global.asax:
    > protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    > {
    > Response.Write("Request authenticated: " + (Request.IsAuthenticated ? 
    > "yes"
    > : "no") + "<br>");
    >
    > if (Request.IsAuthenticated)
    > {
    > string[] roles = new string[] {"ChangeUser", "MoveUser"};
    >
    > Thread.CurrentPrincipal = new GenericPrincipal(Context.User.Identity,
    > roles);
    > }
    > }
    >
    > As I understand it, this should assign the "ChangeUser" and "MoveUser" 
    > roles
    > to the authenticated user, but it doesn't seem to work (or I am doing
    > something wrong). In my web form I have this:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if (Context.User.IsInRole("ChangeUser"))
    > {
    > Response.Write("<br>User is in role \"ChangeUser\"");
    > }
    > if (Context.User.IsInRole("MoveUser"))
    > {
    > Response.Write("<br>User is in role \"MoveUser\"");
    > }
    > }
    >
    > This does not print out the "User is in role ..." as I would expect it to.
    > Any suggestions? 
    

  • Next message: James McFarland: "FormsAuthentication Roles Problem"

    Relevant Pages

    • Roles not working
      ... protected void Application_AuthenticateRequest(Object sender, EventArgs e) ... to the authenticated user, but it doesn't seem to work (or I am doing ...
      (microsoft.public.dotnet.framework.aspnet.security)
    • Problem Loading Data in to a Textbox located in MultiView that is in a Login View
      ... View to the Profile View and enter their profile infomation and save ... protected void Page_Load(object sender, EventArgs e) ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: PagerTemplate dissapearing
      ... My solution was to add the following pagertemplate: ... protected void gridview1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) ... GridView grid = sender; ...
      (microsoft.public.dotnet.framework.aspnet)
    • Weird session state problem, maybe?
      ... protected void myRepeater_ItemDataBound(object sender, ...
      (microsoft.public.dotnet.general)
    • RE: Programmatic Dropdown and SelectedIndexChanged event
      ... protected void Page_Load ... void ddl2_SelectedIndexChanged(object sender, EventArgs e) ... Microsoft Online Community Support ...
      (microsoft.public.dotnet.framework.aspnet)