It is very useful in. NET we can user framework provided role Manager, and easily configure in Web. config.
However, I find when I fullfil such configure:
<rolemanager defaultprovider= "Qqmgssqlprovider" enabled= "true" cacherolesincookie= "true" Cookiename= ". Asproles " cookietimeout=" " cookiepath="/" cookierequiressl=" true " cookieslidingexpiration=" True " cookieprotection=" All "> <providers> <add name=" Qqmgssqlprovider " type = "System.Web.Security.SqlRoleProvider" connectionstringname= "Twitterdbcontext" applicationname= " Twitter "/> </providers> </roleManager>
When I send the Http request, I find the error:
{"Message": "An error has occurred.", "Exceptionmessage": "The Role Manager feature have not been enabled.", "Exception Type ":" System.Configuration.Provider.ProviderException "," StackTrace ":" at System.Web.Security.Roles.EnsureEnabled () \ r \ n @ Twitter.App.Controllers.APIControllers.PingController.Get () in C : \\Users\\Administrator\\Downloads\\Twitter-master\\Twitter-master\\QQmgs.App\\Controllers\\APIControllers\\ PingController.cs:line 19\r\n at Lambda_method (Closure, Object, object[]) \ r \ n at System.web.http.controllers.reflectedhttpactiondescriptor.actionexecutor.<>c__displayclass10.b__9 (Object instance, object[] methodparameters) \ r \ n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync (Httpcontrollercontext controllercontext, IDictionary ' 2 arguments, CancellationToken cancellationtoken) \ r \ n---End of Stack trace from previous location where exception is thrown---\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.Thro Wfornonsuccess (Task Task) \ r \ nT System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task Task) \ r \ n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext () \ r \ n---End of stack trace from previous Location where exception is thrown---\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (Task Task) \ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (task Task) \ r \ n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext () \ r \ n---End of stack trace from previous location where Exception was thrown---\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (task Task) \ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task Task) \ r \ n System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext () \ r \ n---End of stack trace from previous Location where exception is thrown---\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (TAsk task) \ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (task Task) \r\ N at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext () "}
So, after my investigation, I find there's one more thing I should do.
"It looks like your membership database was missing some required procedures required for the membership system.
You need to run VS command prompt and type this command "Aspnet_regsql.exe" and link it to your database. This command would populate your database with all required database objects for the membership system. "
Refer to:https://forums.asp.net/t/2048614.aspx?could+not+find+stored+procedure+dbo+aspnet_checkschemaversion+
After I follow the instruction below, I find in my database there's some new tables like: "Aspnet_roles, Aspnet_membership ".
Then I resend the Http request to test, succeeded!
ASP. NET Role Manager tutorial