1

After many attempts to use roles management in an ASP.NET project, I am in need of help.

I have a local SQL Server set up, and here are some parts of my web.config file...

<connectionStrings>
   <add name="DefaultConnection" 
        providerName="System.Data.SqlClient" 
        connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-WebSite2-20130703132914;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-WebSite2-20130703132914.mdf"/>
   <add name="SqlRoleManagerConnection" 
        connectionString="Data Source=my-pc;&#xA;Initial Catalog=aspnetdb;Integrated Security=SSPI;"/>
</connectionStrings>

<roleManager enabled="true">
  <providers>
    <add name="DefaultRoleProvider" 
         connectionStringName="DefaultConnection" applicationName="/"   
         type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add name="SqlRoleManager" 
         connectionStringName="SqlRoleManagerConnection" applicationName="/" 
         type="System.Web.Security.SqlRoleProvider"/>
  </providers>
</roleManager>

The application is called WebSite.

aspnetdb is already set up on the local database and is ready to manage roles...

When I go to the ASP.NET configuration option in visual studio 2012 express, under security, it tells me that it cannot connect to the database.

I'm guessing the problem is in my web.config file, but I am not sure... Any help would be appreciated!

2 Answers 2

1

You need to defaultProvider attribute. It says which provider you are going to use by default.

<roleManager enabled="true" cacheRolesInCookie="false" 
defaultProvider="DefaultRoleProvider">
  <providers>
    <clear/>
    <add connectionStringName="DefaultConnection" applicationName="/" 
name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

    <add connectionStringName="SqlRoleManagerConnection" applicationName="/" 
name="SqlRoleManager" type="System.Web.Security.SqlRoleProvider"/>
  </providers>
</roleManager>
Sign up to request clarification or add additional context in comments.

1 Comment

Okay, I will try this today!
0

Do not configure two connectionStrings and two providers. If you must, configure which one is the default provider.

Read more: http://msdn.microsoft.com/en-us/library/ff647401.aspx#paght000013_step2

1 Comment

Okay I'll take out the one I don't need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.