ASP.NET Web 管理工具自定义数据库
我在这里陷入了一个问题,需要有人的提示。 我使用自己的 SQL Server 数据库来管理用户和角色(而不是 aspnet DB)。它工作正常,直到我向 aspnet_membership 表添加一些自定义字段。这样做后,我无法通过 asp.net Web 管理工具创建新用户。抛出以下异常:
遇到错误。请返回上一页并重试。
以下消息可能有助于诊断问题:调用的目标已引发异常。在System.RuntimeMethodHandle._InvokeMethodFast(对象目标,Object []参数,SignatureStruct&sig,MethodAttributes methodAttributes,RuntimeTypeHandle typeOwner)在System.RuntimeMethodHandle.InvokeMethodFast(对象目标,Object []参数,Signature sig,MethodAttributes methodAttributes,RuntimeTypeHandle typeOwner)在System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化,布尔skipVisibilityChecks)在System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数、 CultureInfo 文化)位于 System.Web.Administration.WebAdminMembershipProvider.CallWebAdminMembershipProviderHelperMethodOutParams(字符串方法名称、对象 [] 参数、类型 [] paramTypes) 位于 System.Web.Administration.WebAdminMembershipProvider.CreateUser(字符串用户名、字符串密码、字符串电子邮件、字符串密码问题,字符串passwordAnswer,布尔值isApproved,对象providerUserKey,MembershipCreateStatus&状态)在 System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() 在 System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) 在 System.Web.UI.WebControls.Wizard.OnBubbleEvent(对象源,EventArgs e) )在System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(对象源,EventArgs e)在System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(对象源,EventArgs args)在System.Web.UI.Control。 RaiseBubbleEvent(对象源,EventArgs args)在System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)在System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串eventArgument)在System.Web.UI.WebControls.Button .System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) 在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) 在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) 在 System.Web。 UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
这仅在用户创建时发生。其他一切都工作正常。我已经尝试再次运行 aspnet_regsql 实用程序。还有其他建议吗?任何帮助将不胜感激。
-- 阿里
I am stuck into a problem here and need a hint from someone.
I am using my own SQL Server database for managing users and roles (as opposed to aspnet DB). It was working fine until I added some custom fields to the aspnet_membership table. After doing so, I cannot create a new user through the asp.net web administration tool. The following exception is thrown:
An error was encountered. Please return to the previous page and try again.
The following message may help in diagnosing the problem: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Web.Administration.WebAdminMembershipProvider.CallWebAdminMembershipProviderHelperMethodOutParams(String methodName, Object[] parameters, Type[] paramTypes) at System.Web.Administration.WebAdminMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) at System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() at System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
This occurs only at the time of user creation. Everything else is working fine. I have already tried running the aspnet_regsql utility again. Any other suggestions? Any help will be most appreciated.
--
Ali
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
猜测一下,您添加的任何字段是否定义为 Not NULL 并且没有默认值?
如果是这样,请确保在添加用户的代码中填充它们。
At a guess, are any of the fields you have added defined as Not NULL and have no defaults?
If so, make sure you populate them in the code that addes a user.
额外的列是否允许保存空值?如果没有,您是否定义了合适的默认值?
您是否更新了写入成员资格表的存储过程?如果是这样,那么您需要编写一个自定义会员资格提供程序填充它们——它们是什么样的细节?
最好将这些值存储在配置文件中用户 - 除非他们明确与其会员资格有关,其中自定义提供程序是最佳选择。
编辑以回复阿里的评论< /strong>
在这种情况下(将帐户标记为已删除/非活动),那么是的,将其存储在成员资格表中可能是有意义的 - 它们与网站的用户成员资格有关。
但是 - 我在您的方法中看到的主要问题是,如果您使用默认的登录控件,用户仍然可以最初登录,然后您需要检查 LoggingIn 中的已删除字段的值(在身份验证之前)或 LoggedIn (之后)事件处理程序 - 您可能可以通过修改内置的
IsApproved
属性默认处理此问题。Are the extra columns allowed to hold null values? Have you defined suitable default values if they aren't?
Did you update the Stored Procedures that write to the membership tables? If so, then you'll need to write a custom membership provider to populate them - what sort of details are they?
It would probably be better to store these values against a Profile for the user - unless they are explicitly to do with their membership, in which a custom provider is the way to go.
Edit to respond to Ali's comments
In that instance (marking an account as deleted/inactive) then yes, it probably makes sense to store that against the membership table - they are to do with the users membership of the site.
However - the main issue I can see with your approach is that if you're using the default Login controls, the user can still log in initially, and then you'd need to be checking the value of the Deleted field in either the LoggingIn (before Authentication) or LoggedIn (after) event handlers - you might be able to get away with modifying the built in
IsApproved
property to handle this by default.谢谢扎夫和奥德。 NULL 值是有问题的。
但扎夫指出了我想了解更多的另一个问题。其他详细信息就像 isDeleted 一样,我只需将 isDeleted 标记为 true,而无需实际删除用户,然后是一些相关的审核详细信息,如deletedByUser、dateDeleted 等(以及一些特定于应用程序的)。
我没有更新写入成员资格表的存储过程。相反,我有一些额外的 SP,它们会在创建用户后立即填写额外的详细信息。那(在成员资格表中存储字段并编写新程序)是正确的方法吗?
Thanks Zhaph and Oded. The NULL values were problem.
But Zhaph pointed out towards another issue I would like to know more. The additional details are like isDeleted, where I just mark isDeleted as true without actually having to delete the user and then some relevant details for audit like deletedByUser, dateDeleted etc. (and some application specific).
I did not update the stored procedures that write to the membership tables. Instead, I have some additional SPs which fill in the extra details as soon as the user is created. Is that(storing field in membership table and writing new procedures) a correct way to approach?