9

I'm trying to get authorization working on asp.net mvc4, so I try to use WebSecurity.

WebSecurity.InitializeDatabaseConnection("tradefairindia", "Users", "Id", "Username", false);

I've put this into Global.asax, and this is where the error comes, "Default Role Provider could not be found".

On the internet I read that I had to add this line of code to my web.config <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">. But I had it added already because of previous errors.

How can I resolve this problem??

Edit:

When I change it to defaultProvider="SimpleRoleProvider" it gives me a new error. It says

The type or namespace name 'Data' does not exist in the namespace 'WebMatrix' (are you missing an assembly reference?)

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
user1534664
  • 3,258
  • 8
  • 40
  • 66

1 Answers1

19

I fixed it by changing the defaultProvider to SimpleRoleProvider. The second error I fixed by adding Webmatrix.data as a reference, and going to its property's and put copy local on true. I dont know how this fixes it, if anyone can elaborate that would be nice.

Here is my web.config for anyone who bumps into the same prob:

<system.web>
    //...
    <membership defaultProvider="SimpleMembershipProvider">
      <providers>
        <clear />
        <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="SimpleRoleProvider">
      <providers>
        <clear />
        <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
      </providers>
    </roleManager>
    //...
</system.web>
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
user1534664
  • 3,258
  • 8
  • 40
  • 66
  • 1
    Don't forget to accept your own answer. This should help a lot of people. – Erik Philips Jul 31 '13 at 20:32
  • 3
    You can chose whatever name, like `defaultProvider="MyRoleProvider"`, as long as the name corresponds to one in the `` section. There you specify what library is actually used. So in `` you say you want to use the SimpleRoleProvider from the WebMatrix.WebData library, and that you call it 'MyRoleProvider'. If you don't set Copy Local to True WebMatrix.WebData.dll won't be copied to your bin folder when you compile. Since it's not part of the GAC by default, your assembly can't find it. – flip Oct 26 '13 at 15:08