views:

365

answers:

3

Hi all, 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

+1  A: 

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.

Oded
+1  A: 

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.

Zhaph - Ben Duguid
A: 

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?

Ali
You should have enough rep to upvote answers now, if you'd like to do that.
Greg