How do I access the default SqlProvider in a DAL? I've only ever done this before from webforms.
+1
A:
With the following
using System.Web.Security;
....
SqlRoleProvider roleProvider = new SqlRoleProvider();
string[] roles = roleProvider.GetAllRoles(); //for example to get all role names
EDIT
To configure your application to use the SqlRoleProvider you'll need to add the following under the <system.web>
section of your web.config file.
<roleManager enabled="true" defaultProvider="SqlRoleManager">
<providers>
<add name="SqlRoleManager"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="MyConnectionStringName" //change this to the name of your connection string
applicationName="MyApplication" />
</providers>
</roleManager>
mdresser
2010-07-06 10:07:16
Great, thanks. Now, the config for the provider is in the web site client, so how do I get reconcile the connection string?
ProfK
2010-07-06 15:22:18
Hi, see my edits above. Hopefully this should clarify things.
mdresser
2010-07-06 15:47:28
Thanks @mrdresser, but I have that in my web.config, but my code that uses the provider is not in the web site project.
ProfK
2010-07-06 16:33:42
Is your DAL built as a DLL which is referenced by the website project? If it is, then you should just need to add these settings to the website's web.config. If your DAL code is running in a different process (e.g. it's a separate web service or something), then you should just have to add the same setting to your other config file surely.
mdresser
2010-07-06 16:58:45