1

So, I have been searching all over the internet for a solution. I've done a lot of research and it has only left me more lost. I am creating an MVC 5 site for Azure and I am having trouble setting up Role Management.

When I use the Roles object I get an error of "Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'" I found this link but I don't know how it would apply to Azure.

My web.config file is currently set up like this.

<add name="RoleDB" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Techdb3.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

    <roleManager enabled="true">
  <providers>
    <clear/>
    <add connectionStringName="RoleDB"
     name="AspNetSqlRoleProvider"
     type="System.Web.Security.SqlRoleProvider"
     applicationName="TechAndGames" />
  </providers>
</roleManager>
Community
  • 1
  • 1
David Price
  • 170
  • 1
  • 16
  • And you use Web Sites, or Web Role?! And how did you initialize this database (techdb3)? – astaykov Oct 17 '14 at 16:52
  • I believe I may not know what Web roles are compare to web sites. The database is code first and I simply point it at my Azure MS SQL server. – David Price Oct 18 '14 at 01:25

1 Answers1

3

For MVC 5, you need to remove the roleManager tag, I think. I was using <roleManager> in my latest MVC 5 application and was getting the exact same error as you. As soon as I removed it, the error went away. I think this is because MVC uses a different role management approach.

A couple of other things: make sure you have the proper tables setup in your database. These are the tables you will need:

  • _MigrationHistory
  • AspNetRoles
  • AspNetUserClaims
  • AspNetUserLogins
  • AspNetUserRoles
  • AspNetUsers

You may not need all of these, depending on what you are doing. To get these setup properly, I (1) created a new project with the MVC 5 template, (2) ran the project locally (3) went through the registration process of a new user on the site and (4) looked in my local SQL server (LocalDb)\v11.0 and it had created a database there with all the tables I mention above. I then scripted those tables out and ran the scripts against my real database.

Then, in your application you should be able to call User and get access to methods like User.IsInRole("someRole");.

joshmcode
  • 3,471
  • 1
  • 35
  • 50
  • 1
    I believe this was exactly my problem I forgot to update my findings. Yes if you keep the tag in the configuration I believe the server attempts to revert to an older version of "roleManger" which used to require a call to create all of the necessary tables. – David Price Oct 19 '15 at 21:54
  • Glad to hear you figured it out :-) – joshmcode Oct 19 '15 at 22:07
  • I know this is old but it just saved me after several days of frustration trying to get my MVC 5 Identity project running on an 3rd party hosting server. – Caverman Aug 19 '18 at 04:23