|
This evening I was plugging away at ASP.NET MVC 1.0 and I kept having a really weird problem with the default implementation of AccountController. Every time I tried to log in, I was getting some kind of annoying error about the "rememberMe" parameter being null.
I don't really know how this one slipped through the cracks and its more of a nitpick than a real bug, but it is application-breaking nonetheless. All you have to do in order to see the bug is attempt to log into the default ASP.NET MVC project after creating it and don't check the "remember me" box. I guess that edge case never got tested ;)
Anyway, the fix is quite easy. I just modified the signature of the LogOn method in AccountController to look like this:
public ActionResult LogOn(string userName, string password, bool? rememberMe, string returnUrl)
Notice that rememberMe is now a nullable parameter. Now you can't pass a nullable bool to the actual implementation of the LogOn method in the forms authentication service they provide, so you can just do something like this to pass along the appropriate information:
FormsAuth.SignIn(userName, rememberMe == true);
This will give you a meaningful default value of false.
Again, given the ridiculously high quality of ASP.NET MVC 1.0, I'm not really sure how this slipped through other than the idea that maybe most people yank out the default AccountController or all of the testers checked "remember me" :) Either way, it's a 30 second fix.