MVC4: UserIsInRole - Unable to connect to SQL Server database

后端 未结 3 1412
执念已碎
执念已碎 2020-12-13 21:40

Breaking my head around with this, yesterday it worked fine and today it seems to be broken:

This line is generating the error:

@if (Roles.IsUserInRo         


        
相关标签:
3条回答
  • 2020-12-13 22:09

    For my use case, adding the following line in the web.config file fixed it!

    <appSettings>
      <add key="enableSimpleMembership" value="false"/>
    </appSettings>
    
    0 讨论(0)
  • 2020-12-13 22:14

    Adding this:

    [InitializeSimpleMembership]
    

    To the top of the HomeController fixes the issue.

    Explanation on the attribute:

    http://blogs.msdn.com/b/rickandy/archive/2012/08/15/initializesimplemembership-attribute-and-simplemembership-exceptions.aspx

    0 讨论(0)
  • 2020-12-13 22:25

    I found that using UserManager.IsInRole(User.Identity.GetUserId(), "Admin") solved the problem for me. Cheers

    0 讨论(0)
提交回复
热议问题