Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to make SqlRoleProvider.ApplicationName thread safe

Reply
Thread Tools

how to make SqlRoleProvider.ApplicationName thread safe

 
 
Francis Reed
Guest
Posts: n/a
 
      04-07-2006
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


 
Reply With Quote
 
 
 
 
wfairl@gmail.com
Guest
Posts: n/a
 
      04-07-2006
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.

 
Reply With Quote
 
 
 
 
Erik Funkenbusch
Guest
Posts: n/a
 
      04-08-2006
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
html5lib not thread safe. Is the Python SAX library thread-safe? John Nagle Python 5 03-12-2012 04:07 PM
Re: How to Easily Make a Function Thread-Safe CBFalconer C Programming 14 01-13-2009 10:45 PM
Re: How to Easily Make a Function Thread-Safe Ian Collins C Programming 4 01-13-2009 06:43 AM
os.ChDir() not thread-safe; was : Is tempfile.mkdtemp() thread-safe? Gabriel Rossetti Python 0 08-29-2008 08:30 AM
Metaclass to make all methods of a class thread-safe Irmen de Jong Python 5 09-28-2004 06:01 PM



Advertisments