Default Role Provider could not be found when using SimpleMembershipProvider

青春壹個敷衍的年華 提交于 2020-01-02 01:37:06

问题


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?)


回答1:


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>


来源:https://stackoverflow.com/questions/17980030/default-role-provider-could-not-be-found-when-using-simplemembershipprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!