I have a centralized membership database that stores roles for different MVC applications. In other MVC applications, I can just put the below snippet in web.config to associate roles to the User object and then I can just use “User.IsInRole(Role.Admin)” to check a user’s role.
<roleManager defaultProvider="SqlProvider"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="true"
cookieSlidingExpiration="true"
cookieProtection="All" >
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="SqlServices"
applicationName="SampleApplication" />
</providers>
</roleManager>
The above method doesn’t seem to work in .NET core. The role provider that I declared is getting ignored. How do I use SqlRoleProvider in .NET core?
Note: this application doesn't actually create any user/role. It just needs to read from that membership database and authorize users based on their roles.