MVC Membership Starter Kit Released
// August 7th, 2009 // MVC
Almost six months after the official release of Asp.Net MVC 1.0 and nearly a year after the last release of the starter kit, I’ve finally rewritten and released the Asp.Net MVC Membership Starter Kit. If you’re already familiar with what it is and want to grab it, you can find the release on the CodePlex project site:
http://mvcmembership.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22875
What is the Asp.Net MVC Membership Starter Kit?
The starter kit currently consists of two things:
- A sample website containing the controllers, models, and views needed to administer users & roles.
- A library that provides testable interfaces for administering users & roles and concrete implementations of those interfaces that wrap the built-in Asp.Net Membership & Roles providers.
Out of the box, the starter kit gives you the following features:
- List of Users
- List of Roles
- User Account Info
- Change Email Address
- Change a User’s Roles
How do I use it?
In Asp.Net MVC 1 there isn’t a great story for packaging & sharing controllers, views, and other resources so we’ll need to follow a few manual steps:
- After getting the source code build it using your preferred IDE or using the included Build.Debug.bat or Build.Release.bat batch files.
- Grab the MvcMembership.dll assembly and place it wherever you’re including external libraries in your project. Add a reference to the assembly to your Asp.Net MVC application.
- Copy the UserAdministrationController.cs file from the SampleWebsite‘s Controllers directory to your app’s Controllers directory.
- Copy the ISmtpClient.cs file, SmtpClientProxy.cs file, and UserAdministration folder from the SampleWebsite‘s Models folder to your app’s Models folder.
- Copy the UserAdministration folder from the SampleWebsite‘s Views folder to your app’s Views folder.
- Make sure you’ve configured your web.config properly for Membership and Roles. If you aren’t sure of how to do this, take a look at the first two articles in this series by Scott Mitchell at 4GuysFromRolla.
- Finally, add the following code to your global.asax to keep the membership system updated with each user’s last activity date:
protected void Application_AuthenticateRequest()
{
if(User != null)
Membership.GetUser(true);
}
What is new since the last release?
Well, the last release was for Preview 5, so at the very least the project has been updated for Beta and finally Release. Moreover, the project has been completely rewritten from scratch – a major undertaking that was the primary cause of the long delay between releases. Why the rewrite? Two reasons:
- The first release of the Starter Kit was for Preview 2 of the MVC framework. A lot changed between Preview 2 and Release – A LOT. A lot of the features of the first starter kit were rolled into the OTOB experience (such as login and registration), so I shifted the scope of the project more squarely into the realm of user & role administration. Unfortunately all of these major changes took a toll on the source – I was no longer happy working in the source as it was written for many reasons and thus wanted a rewrite. One of those reasons was…
- Previous releases had no (as in zero, less than one, nada) unit tests. This became increasingly unacceptable to me and trying to add unit tests after-the-fact was a nightmare. Instead I rewrote the project using TDD.
Alright, so that was basically the long-winded spiel to prepare you for the bad news: the project regressed from a functionality perspective. During the course of the rewrite things some things didn’t make it in – chief among them is the OpenID integration. I encourage everyone to take a look at the Maarten Balliauw (an MvcMembership contributor) blog post on authenticating via RPX in MVC.
What comes next?
The primary motivator for me getting off my but after nearly a year and finishing up this release is my desire to convert it to an “area” for use in MVC 2. Packaging reusable components like this has been a sore spot for the current MVC framework and I’m glad to see the blue badges are going to provide a common solution. Along with that I’ll likely try to add RPX authentication ala Maarten’s post.




Asp.Net MVC Membership Starter Kit Released…
Thank you for submitting this cool story – Trackback from DotNetShoutout…
[...] This post was Twitted by maartenballiauw [...]
MVC Membership Starter Kit Released | SquaredRoot…
DotNetBurner – burning hot .net content…
[...] This post was Twitted by dingwallr [...]
[...] MVC Membership Starter Kit Released | SquaredRoot [...]
You are voted!
Track back from WebDevVote.com
[...] MVC Membership Starter Kit Released | SquaredRoot Posted in ASP.NET, MVC. Leave a Comment » [...]
The only thing i dont’t like is that you coupling it to your own IPagedList
But, great job! thanks!
@Alfredo – I’m open to suggestions for better ways to handle paging, since it sounds like you have an alternative.
Also, I can’t take full credit for IPagedList as it was originally written by Scott Guthrie (and then I found it via Rob Conery).
Hi Troy don’t get it in wrong way ;P I love your work, it was just a little point.
Yes I’m using very similar aproach for pagination (just different names of properties), then i have to change, my code or yours.
And thats what i did, but i think the best solution is let the count variable totalUserCount get out and handle the pagination out the membershipkit.
But i’m a begginer and maybe is the worst solution (don’t eat me!)
Hopefully the framework will include a paginated list class that we all will follow
@Alfredo – Luckily IPagedList implements IEnumerable *and* provides the total count, which should make it easy to transform from IPagedList to IAlfredoPagedList in the controller. As an example, in the controller’s Index method you could do the following:
// get my IPagedList version from the service usersPagedList = _userService.FindAll(index ?? 0, PageSize);
IPagedList
// transform it into your custom paged list implementation usersAlfredo = new AlfredoPagedList ();
IAlfredoPagedList
foreach(var user in usersPagedList){ usersAlfredo.Add(user); }
// get total user count
int totalUsers = usersPagedList.TotalItemCount;
As for “i think the best solution is let the count variable totalUserCount get out and handle the pagination out the membershipkit”, I have to disagree. Which is easier:
(a) letting someone that has their own paging implementation (such as yourself) rip out the provided paging and put in their own
(b) making everyone that does not yet have their own paging implementation go out and find one or create their own
In my opinion option (b) is helpful to far more people and it doesn’t severely impact the option (a) people (I can’t say the same about the vice-versa).
Troy,
if I need to add a custom field say birthday for the user how do I do it with your Starter Kit?
@Firefly: Keep in mind my starter kit is just built on top of the .Net Membership system. The Membership system doesn’t support custom fields, but Microsoft provides a separate system for that: the Profile system. More information can be found here:
http://www.4guysfromrolla.com/articles/101106-1.aspx
@Troy, thanks for the quick reply. That’s what I thought too. If I create a custom provider how can I tie it into your starter kit? Of course I can query my own provider directly but if there is some painless way to tie them together then I would love know.
@firefly: You don’t need to create a custom membership provider, that can stay as-is. What you’ll want to do is just customize the Details action on the UserAdministration controller to retrieve your profile settings and pass it to the view. Then you’ll obviously need to modify the Details view to display the profile data as well. Unfortunately no magic built in to handle it for you, maybe in a future version. =)
@Troy Thanks for the quick reply. After some research, btw thanks for the links. I’ve decided to roll my own. The build in profile provider leave a lot to be desire, especially in the way they store data in a single row. Thanks for the starterkit though. I’ll refer back to it as an example.
Thanks for your work on this Troy. Just wondering if anyone has tried this with ActiveDirectoryMembershipProvider ? I tried it, but I get the error: “The property ‘LastActivityDate’ is not supported by the Active Directory membership provider.” Any help would be appreciated!
@robnardo: Interestingly enough, any attempt to even *read* from the LastActivityDate property of the MembershipUser object will throw a NotSupportedException (http://msdn.microsoft.com/en-us/library/system.web.security.activedirectorymembershipuser%28VS.85%29.aspx).
The only short-term fix I can offer is that you modify the Index.aspx and Details.aspx views to remove any references to the LastActivityDate property. Because this is surely a somewhat common scenario, future versions of the project should offer an easier way to supress this issue. I’ve started an Issue on the CodePlex project to track the issue’s status:
http://mvcmembership.codeplex.com/WorkItem/View.aspx?WorkItemId=4054
Thanks for bringing it to my attention!
So will this work with the MVC 2 preview that was recently released?
I’ll double-check when I have a moment, but I believe it should work – yes (though it doesn’t take advantage of any of the new features of MVC 2).
So, do you plan to keep this thing alive as MVC 2 moves ahead? It seems like you are planning to do that. I hate implementing a tool like this, then the author quits working on it.
I do plan to keep it moving, but that doesn’t mean there won’t be lulls in when I’m working on it. The point of this project is to get you setup with the basics needed to administer a membership-oriented website quickly; I expect you’ll want to customize it yourself from there and have geared much of the project around leaving it as open to customization as possible.
Great work Troy, and thanks for posting this.
I’ve been trying to use your assembly and project files with my app, but I keep getting a compilation error for IndexViewModel.cs file – ‘The type or namespace name IPagedList does not exist in the namespace System.Web.Mvc’ I have tried Rob’s method and have also added the reference to PagedList assembly which was suggested by the VS.
What am I missing here? I’m usre your code works, but I guess I’m doing something wrong.
Two things:
* The link in codeplex to this blog gives a 404
* I’ve migrated the code to VB. Since the Controller code needs some work after the automatic translation, I’ve posted it here: http://codepaste.net/69z5rn if anyone else want it.
Great post Troy, very nice write up and I appreciate the Starter Kit approach. Thanks!
@Dhruv – You’ll indeed want to reference the PagedList assembly packaged with MvcMembership. After downloading the release and unzipping it, look inside the “References” subdirectory.
@eduardo: I just double-checked all the links and didn’t get any 404s. Maybe it was a temporary CodePlex issue? If you see it again, please let me know.
Thanks for posting the VB version for whomever needs it!
@Steve Trefethen:
Thanks Steve, glad you like it. Let me know if you have any issues or suggestions.
[...] del blog de Troy Goode hay varios post al respecto de su participación en esta implementación de las clases de [...]
[...] del blog de Troy Goode hay varios post al respecto de su participación en esta implementación de las clases de [...]
Hi Troy,
I tried to open the solution in VS 2010 RC and upon conversion, the SamplteWebsite.csproj failed stating ‘The project type is not supported by this installation’.
What type of project is it?
Note, I don’t have MVC 1.0 isntalled, but from the article it was sounding like it was compatable with latest MVC 2 (or at least some flavor of MVC 2).
Thanks in advance.
The link in codeplex that says, “Screenshots available on my blog” is still leading me to a 404 page.
I noticed this:
Codeplex link: http://www.squaredroot.com/2009/08/06/mvcmembership-release-1-0/
This post: http://www.squaredroot.com/2009/08/07/mvcmembership-release-1-0/
The dates are different, 2009/08/06 and 2009/08/07.
Great work btw.
Could you provide a download of a MVC 2 compatible project?
Tommy, You can creat your own project in MVC 2 and add the classes and references from MVCMemebership project. It works for me.
Thanks
Terry, Tommy, & Mavi:
The project has now been updated to MVC 2, VS2010, & .NET4. Source hosting is now at GitHub instead of CodePlex:
http://github.com/TroyGoode/MembershipStarterKit
Diego: I’ve moved my source control hosting from CodePlex to GitHub, and as part of that process I’ve updated the screenshots link to point to this post. Thanks for bringing it to my attention!