gpt4 book ai didi

c# - 更新成员(member)属性。不支持的方法

转载 作者:行者123 更新时间:2023-11-30 15:02:00 24 4
gpt4 key购买 nike

我已经尝试研究我遇到的异常几个小时了,但没有任何进展。

我只是尝试使用以下代码更新成员(member)资料:

MembershipUser user = Membership.GetUser(username);
user.IsApproved = false;
Membership.UpdateUser(user);

所以问题出在上面代码示例的最后一行。服务器抛出异常,指出不支持指定的方法。我没有构建错误,我相信我使用的是正确的库。

知道为什么会发生这样的事情吗?

Server Error in '/' Application.

Specified method is not supported.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Specified method is not supported.

Source Error:


Line 58: MembershipUser user = Membership.GetUser("asdf", false);
Line 59: user.IsApproved = false;
Line 60: Membership.UpdateUser(user);
Line 61:
Line 62: // -----------------

Source File: d:\Coding\ASP.NET\Source\Controllers\AccountController.cs Line: 60

Stack Trace:


[NotSupportedException: Specified method is not supported.]
WebMatrix.WebData.SimpleMembershipProvider.UpdateUser(MembershipUser user) +38206
System.Web.Security.MembershipUser.Update() +91
System.Web.Security.Membership.UpdateUser(MembershipUser user) +19
Source.Controllers.AccountController.Register(RegisterModel model) in d:\Coding\ASP.NET\Source\Controllers\AccountController.cs:60
lambda_method(Closure , ControllerBase , Object[] ) +180
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

7929

最佳答案

SimpleMembership,顾名思义,非常简单,并没有实现所有的MembershipProvider方法;只是 MVC 基本身份验证和授权所需的那些。如果您尝试使用未实现的方法,您将得到该异常。您可以从头开始创建自己的 MembershipProvider,也可以继承 SimpleMembership 并实现未实现的方法。

关于c# - 更新成员(member)属性。不支持的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13182190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com