how to make SqlRoleProvider.ApplicationName thread safe

Discussion in 'ASP .Net' started by Francis Reed, Apr 7, 2006.

  1. Francis Reed

    Francis Reed Guest

    Hi

    I'm currently working on a new portal for an online university, and we need
    write code that manages roles for multiple applications. To tell the
    SqlRoleProvider which Application we are currently managing I am using the
    SqlRoleProvider.ApplicationName Property which is not thread safe. My
    question is how do I make this property thread safe? Here's a sample of the
    code.

    ....

    Roles.Provider.ApplicationName = "Chemistry101";
    Roles.AddUsersToRoles("Bob, Peter", "Student");
    Roles.CreateRole("TeacherAssistant");


    Roles.Provider.ApplicationName = "Chemistry239";
    Roles.AddUsersToRoles("Josh, Sam", "Teacher");
    Roles.AddUsersToRoles("Frank, Hui", "Student");
    Roles.DeleteRole("LabMonitor");

    ....

    Also could anyone tell me if the following class would make the
    ApplicationName Property thread safe?

    public class EconcordiaRoleProvider : SqlRoleProvider
    {
    private static Object mutex = new Object();

    public EconcordiaRoleProvider() : base()
    {

    }

    public override string ApplicationName
    {
    get
    {
    lock(EconcordiaRoleProvider.mutex)
    {
    return base.ApplicationName;
    }
    }
    set
    {
    lock (EconcordiaRoleProvider.mutex)
    {
    base.ApplicationName = value;
    }
    }
    }
    }

    Thank you for the time you have given this post, and I hope to hear from you
    in the near future. If you have any advice or suggestions, please don't
    hesitate to reply to this post.

    Cheers
    Francis
     
    Francis Reed, Apr 7, 2006
    #1
    1. Advertising

  2. Francis Reed

    Guest

    Two things:
    1.) Looks like you're going to be doing a lot more reads than writes,
    use a readerwriterlock
    2.) You should be using an instance variable to lock in your case (
    lock(this)), not a static variable since you're synchronizing a
    non-static resource.
     
    , Apr 7, 2006
    #2
    1. Advertising

  3. On Fri, 7 Apr 2006 11:01:00 -0400, Francis Reed wrote:

    > Hi
    >
    > I'm currently working on a new portal for an online university, and we need
    > write code that manages roles for multiple applications. To tell the
    > SqlRoleProvider which Application we are currently managing I am using the
    > SqlRoleProvider.ApplicationName Property which is not thread safe. My
    > question is how do I make this property thread safe?


    Why do you need it to be thread safe? Do you realize the merely having
    muliple web users using it doesn't violate thread consistency? The only
    reason you would need it to be thread safe is if you are launching
    background threads within your pages, which frankly is a difficult thing to
    track and manage anyways, and generally shouldn't be done unless you really
    know what you are doing.
     
    Erik Funkenbusch, Apr 8, 2006
    #3
    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. =?Utf-8?B?RnJhbmNpcyBSZWVk?=

    SqlRoleProvider

    =?Utf-8?B?RnJhbmNpcyBSZWVk?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,363
    =?Utf-8?B?RnJhbmNpcyBSZWVk?=
    Apr 10, 2006
  2. Max2006
    Replies:
    1
    Views:
    756
    Steven Cheng [MSFT]
    Jun 10, 2008
  3. Gabriel Rossetti
    Replies:
    0
    Views:
    1,328
    Gabriel Rossetti
    Aug 29, 2008
  4. MrGrundh

    Membership.ApplicationName and thread safety.

    MrGrundh, Aug 30, 2006, in forum: ASP .Net Security
    Replies:
    14
    Views:
    327
    Smith
    Mar 30, 2007
  5. John Nagle
    Replies:
    5
    Views:
    475
    John Nagle
    Mar 12, 2012
Loading...

Share This Page