MVC 5 IsInRole Usage on Razor Views: Cannot connect to Database

后端 未结 3 880
长情又很酷
长情又很酷 2021-02-07 18:38

I\'m having issues using the new identity system in MVC 5, my goal is to make use of the User.IsinRole(\"RoleName\") on Views. For example:

@if(User.IsInRole(\"A         


        
相关标签:
3条回答
  • 2021-02-07 18:49

    I managed to get around the problem by removing the following line from my Web Config:

    <roleManager enabled="true" />
    

    This was found when looking after comparing line for line on the following example code:

    https://github.com/rustd/AspnetIdentitySample/tree/master/AspnetIdentitySample

    0 讨论(0)
  • 2021-02-07 18:50

    I was having the same problem, however Stunt's answer wasn't working for me. Tried the answer to this question and that solved the issue.

    For the lazy you can try adding this to your web.config file:

     <system.webServer>
        <modules>
          <remove name="RoleManager" />
        </modules>
      </system.webServer>
    
    0 讨论(0)
  • 2021-02-07 18:51

    Create database on start up of the application. Add the following in the Global.ascx with your dbcontext.

    using (FooContext db = new FooContext()) 
            {
                db.Database.CreateIfNotExists();
            }
    
    0 讨论(0)
提交回复
热议问题