Adding temporal role

Discussion in 'ASP .Net Security' started by aitor, Sep 30, 2008.

  1. aitor

    aitor Guest

    Hello,

    I am doing a management of roles for users. At the beginning every user
    will have only one role. I haven´t used role provider because I don´t want
    to add a new record into the database. I just want to add roles and when I
    restart the application, with the global.asax file will be assigned roles
    that I had at the beginning. How can I do to add roles during the execution?

    Using Roles.AddUserToRole() function doesn´t work because role provider is
    disabled.

    I use this sentence in Global.asax:

    string[] difRoles = new string[1] { "administrator" };


    HttpContext.Current.User = new
    System.Security.Principal.GenericPrincipal(User.Identity, difRoles);

    But if I use this sentence in execution is not working.

    Do you know what sentence should I use to get what I want?

    Thank you.
    aitor, Sep 30, 2008
    #1
    1. Advertising

  2. On Sep 30, 4:30 pm, "aitor" <> wrote:
    > Hello,
    >
    >  I am doing a management of roles for users. At the beginning every user
    > will have only one role. I haven´t used role provider because I don´twant
    > to add a new record into the database. I just want to add roles and when I
    > restart the application, with the global.asax file will be assigned roles
    > that I had at the beginning. How can I do to add roles during the execution?
    >
    >  Using Roles.AddUserToRole() function doesn´t work because role provider is
    > disabled.
    >
    >  I use this sentence in Global.asax:
    >
    >                 string[] difRoles = new string[1] { "administrator" };
    >
    >                 HttpContext.Current.User = new
    > System.Security.Principal.GenericPrincipal(User.Identity, difRoles);
    >
    > But if I use this sentence in execution is not working.
    >
    > Do you know what sentence should I use to get what I want?
    >
    > Thank you.


    I think the code is correct. Where do you call it, I suppose in
    Application_AuthenticateRequest method?

    Try to check after that the roles

    string userData = ticket.UserData;
    string[] roles = userData.Split(',');
    foreach(string role in roles)
    {
    Response.Write("You are: " +role.ToString()+"<BR>");
    }

    or simply

    if (User.IsInRole("administrator"))
    {
    .....
    }

    More about FormsAuthentication
    http://www.eggheadcafe.com/articles/20020906.asp
    Alexey Smirnov, Oct 1, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jesper Stocholm
    Replies:
    2
    Views:
    8,050
    John Saunders
    Aug 23, 2003
  2. Hongzheng Wang

    Is there a temporal object created?

    Hongzheng Wang, Dec 8, 2003, in forum: C++
    Replies:
    5
    Views:
    364
    Rob Williscroft
    Dec 9, 2003
  3. jose luis fernandez diaz

    Template temporal value

    jose luis fernandez diaz, Aug 3, 2004, in forum: C++
    Replies:
    4
    Views:
    370
    Victor Bazarov
    Aug 4, 2004
  4. Bjorn Heimir Bjornsson

    Verifying temporal properties. Need problems.

    Bjorn Heimir Bjornsson, Apr 1, 2004, in forum: Python
    Replies:
    5
    Views:
    289
    Yermat
    Apr 6, 2004
  5. David
    Replies:
    0
    Views:
    877
    David
    Jun 18, 2008
Loading...

Share This Page