F
Francis Reed
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
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