ASP.NET Role Provider

Once again proving that everything comes down to infrastructure, I have a frustrating problem regarding ASP.NET Role provider.  The requirements are very basic – I want a site map that controls menu trimmed based on the user’s role.  The implementation is less than basic.  Using the out-of-the-box Role Provider and Site Map from ASP.NET, I set up my site.  Then, I added some location tags to my web.config to govern what is accessible for the different roles.  Excerpts from my web.config: 


<remove name="LocalSqlServer"/>

<add name="LocalSqlServer" connectionString="server=ActuallyARemoteServer;database=zzzzzz;User ID=yyyyyy;Password=xxxxxx;Connect Timeout=30" providerName="System.Data.SqlClient"/>

And the 2 providers:

<siteMap defaultProvider="default" enabled="true">



<add name="default" type="System.Web.XmlSiteMapProvider" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>





<remove name="AspNetSqlMembershipProvider"/>

<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" passwordFormat="Hashed" maxInvalidPasswordAttempts="25" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>



And some resources. 

<location path="Default.aspx"> <system.web> <authorization>

<allow users="*"/>

</authorization> </system.web> </location>

<location path="Public"> <system.web> <authorization>

<allow users="*"/>

</authorization> </system.web> </location>

<location path ="Musician"> <system.web> <authorization>

<deny users="*"/>

<allow roles="Musician"/>

</authorization> </system.web> </location>


Interestingly, nothing showed on my menu bar until I added the "roles" attribute to the root node:

<siteMapNode url="" title="My Application Home" description="" roles="*">

 Which seems odd to me – but I’ll research some other day

The problems are now infrastructure.  I start up my Website Administration Tool and it points to the remote server and I add a role no problem.  When I try and add a user though, it bombs with this error message. 
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 seems odd to me – b/c the Roles are persisting fine.  I did a quick search on WebAdminMembershipProvider.CreateUser Error with Google/Bing and I found this link, which seems to be my problem.
Remove local ASPDB – Check
Add Machine Key – Check
Works – Not Check
Grrrr.  I’ll probably post there next.

3 Responses to ASP.NET Role Provider

  1. Robert says:

    Jamie, I would recommend that you point your local project temporarily to your production website, THEN use that website administration tool on your "local" website, which points to your production database. This should then allow you to add users or groups. hope that helps!

  2. James says:

    That is what I am doing – the remove localSQLServer in the ConnectionStrings Section and the Provider points to that. I run it locally but I am still getting the error message. It just seems odd that I can add a role but not a user. I am wondering if there is some attribute of the user (password strength,etc..) that the WSAT does not check and the "real" inner exception is not being displayed….

  3. James says:

    I found the answer – I added an additional field to the users table in ASPDB that was not null. Therefore, the user insert threw a not null exception but the WSAT does not display the inner exception – so I had to hunt and guess. I figured it out by replicating the user insert using the create user wizard on a test form and displaying the inner exception.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: