Asp.net Role manager tutorial

.NET中会员数据库配置问题解决
本文讲述在.NET中使用框架提供的角色管理器并在Web.Config配置时遇到问题。发送Http请求报错,经调查需在VS命令提示符中运行“aspnet_regsql.exe”命令将其与数据库关联,执行后数据库出现新表,重新发送请求测试成功。

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="30"
          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 has not been enabled.",
  "ExceptionType": "System.Configuration.Provider.ProviderException",
  "StackTrace": " at System.Web.Security.Roles.EnsureEnabled()\r\n at 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 was 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.ApiControllerActionInvoker.d__0.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 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 at System.Web.Http.Controllers.AuthenticationFilterResult.d__0.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 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 is 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 will 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 !

转载于:https://www.cnblogs.com/wushuaiyi/p/5980321.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值