The use of RouteValueDictionary in Websecurity.cs CreateUserAndAccount line 259!!!

Apr 2, 2013 at 1:42 PM
Hi All!

After taken down the source code and fiddling around it to match the "old/previuos" membership provider (I'm using MVC4, but with an old aspnet_Membership Database in SQL Express), I wonder why a RouteValueDictionary type is used instead of the plain Dictionary type at code line 259 below. That fact is implied at line 256! To me it makes no sense, since it will complicate the handling of the key/values in the provider. If i pass in a IDictionary<string,object> object as parameter propertyValues, it could easly be passed down! And does it not feel misplaced, since this type is meant to be used in setting up the Route engine at application start, as the MSDN Library documentation implies, and not to be used here!!

251 public static string CreateUserAndAccount(string userName, string password, object propertyValues = null, bool requireConfirmationToken = false)
252 {
253 ExtendedMembershipProvider provider = VerifyProvider();
254 Debug.Assert(provider != null); // VerifyProvider checks this
256 IDictionary<string, object> values = null;
257 if (propertyValues != null)
258 {
259 values = new RouteValueDictionary(propertyValues);
260 }
262 return provider.CreateUserAndAccount(userName, password, requireConfirmationToken, values);
263 }
Apr 2, 2013 at 4:38 PM

In general in cases like this the RouteValueDictionary is used to "parse" an object with properties into key/value pairs. This allows for a nicer syntax for users calling the code. Check out this old blog post I wrote several years ago:

So while yes, using RouteValueDictionary there is a bit odd, it happens to contain very useful functionality that we wanted to use there, so that's why we chose to do it that way.