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: 

<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.
  

Validation Block – Conditional Validation

I ran into an interesting problem today.  I am working on a DTO layer for a project at work and we want to use the Ent Lib Validation Block.  This is an ASP.NET application and ideally we will only use the PropertyProxyValidatior on our UI.  For Required fields, it is very straight forward – use the Date/Time, String Length, etc  Validators.  However, the problem comes when we need to evaluate optional (nullable) fields.  We have a couple of use cases:
prop is null or, if not null, only 4 characters in length
prop is null or, if not null, matches email regex
 
According to this post, The Validation Block does not support conditional validation in its attributes.  You can use Self Validation but then you can’t use the PropertyProxyValdiator as described here.  A search of ASP.NET forums also indicates that it can’t be done as described here.
 
To solve this problem, I came up with some adquate workarounds.  For use case #1, use the string length validation and set the base to 0.  For the second use case, put a conditional character ("|") in a reg exexpression.  For example:  [RegexValidator(@"(^.{0,0}$)|(^.{1,4}$)", MessageTemplate = "Need To Be Empty or 1-4 Characters")].  Note that use case #2 works with string.empty and string = "", but not with string = null.  That is ok, I have to make sure the UI calling code defaults to string.empty and it will work.  If anyone know how to do a regex for null, please pass it along (I search some but then gave up)

Fowler Architectural Patterns

I read the 1st couple of sections of Fowler’s Patterns of Enterprise Application Architecture.  I had trouble grasping his description of Transaction Script so I went ahead and built a project in C#.  I noticed a coupld of things.
 
1) APplication architecture is more about interfaces.  For example, the complex business logic in the Domain Logic Layer is found in RecognitionService.CalculateRevenueRecognition.  Instead of coding the logic in an Select…Case phrase, you can call a stored procedure and have the logic calculate on the database.  Is the application no longer Transaction Script?  If the function’s interface did not change, I would think it is still TS.  Hwoever, the logic is actaully on the data layer – or can part of the data tier have the domain logic?  I don’t see why not because the UI tier often holds the Domain Logic in fat-windows solutions.  ALso, I carved out the domain logic classes from the UI project to it’s own project in the solution.  Did I change the application architecture?
 
This got me thinking about 2-tier and n-tier use cases:
 
UI & DL & DB | SPS & DT where SPS only does CRUD to DT = n-tier
UI & DB | SPS & DT where SPS does CRUD and DL = 2-tier
UI & DB | SPS for CRUD, SPS for DL, & DT = 2-tier
 
Also, I am looking for patterns about types of Business Logic.  Fowler defines Domain Logic and Application Logic.  I don’t know to put rules regarding security  – is that another area, or layered in these 2 buckets.
 
More questions than answers at this point
 
 
 

Christmas Project – Part 2

Most of sound examples I have seen revolve around visualization of the sound wave.  The application architecture has 2 threads – thread #1 plays the music, thread #2 runs as a continual loop.  In that loop, the app polls the sound card’s buffer and reads inforamtion out of that buffer.  Based on that information, it updates the display.  None of the examples I have seen actaully describe that buffer in detail – what each value of the return array means, for example.  I hope to get a better understanding via the MSDN documentation.  Also, I wonder what the maximum speed the mechanical switch of the phiget can run – can it keep up with 8th notes Con Brio?  We soon shall see…
 

Christmas Project – Part 1

In 2007, I put together a basic Holiday light show based on a great article in Coding4Fun by Brain Peek.  For 2008, I wanted to extend concept by reading any sound file and having the circuits respond to ‘major events’ in the audio file – much like the Visualizer in Windows Media Player does.  
 
Step one of the project is to figure out how to capture the sounds with the correct data (frequency, volume, direction) that I can pass to the light switches.  I first looked at using WMP SDK but that does not allow you to access the actual sound waves. 
 
I then looked on Codeplex and there are a bunch of old articles (2003) using Managed DirectSound and .NET 1.1 that allow you to capture the waves and inspect their values.  Unfortunately, they did not explain some of the data strucutres well enough for my needs.  I wondered if there is a more recent SDK with examples from Microsoft that I can use. This  task is not  as easy as it sounds because of the number of SDKs they put out there, the fact that some say they support C# but don’t include any samples or documentation (can you really call that support?), and the fact that some of their samples just don’t work.  Here is a list of the DirectX SDKs:
August 2008 – Only C++ and the samples  don’t work out of the box (missing ‘xaudio2.h’)
June 2008 – Only C++ samples – at least the samples work
March 2008 – Only C++ samples – this is getting annoying
November 2007 – Pre-release of XAudio2.  Only C++ examples
August 2007 – Pre-release of XAudio2.  Eurika!  Managed Samples (though only for .NET 1.1)
June 2007 –
April 2007 –
August 2006 –
 
So it looks like no .NET 2.0+ samples for Managed Code.  I wonder how long until MSFT gives an update.