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:
<connectionStrings>
<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">
<providers>
<clear/>
<add name="default" type="System.Web.XmlSiteMapProvider" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, 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=""/>
</providers>
</membership>
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.