views:

554

answers:

2

I'm designing an ASP.Net application that must support 'SubSites'.

The idea is to have a super admin manage all users, global application settings and SubSites. Each Subsite has a few of its own settings (such as a local admin, logo and welcome message) and each SubSite has its own list of registered users.

This is very similar with what you get using a CMS such as Joomla, SharePoint or DotNetNuke. In fact, I'm tempted to use such a platform, but other project requirements prevent me from doing that.

My questions are very general at this point:

  1. Using ASP.NET 2.0 Membership, how would I designate a super admin and classify users based on the SubSite in which they have registered?
  2. How would I implement SubSites (what patterns should be used, etc)? I'm especially interested in articles that explain how others have done this. I would like to learn the best practices that others have acquired, without spending days digging into the source code of a large open source project like DotNetNuke.

I'll be implementing this in ASP.Net MVC 1.0, so any examples in that regard will be most helpful.


UPDATE: I really like how Mike Hadlow implemented multi-tenancy and I've decided to use his work as a starting point. See this post for info on how I'm using SqlMembershipProvider with each tenant having their own isolated database. That solves my membership "based on subsite" problem.

+2  A: 

Forgive me if I do not understand what "subsite" means, are you using that term to refer to the idea of creating mini-sites within a grand master site? If so, I think I understand what you want to do but I'd have to say that the Membership system in asp.net 2.0 is very much a framework which you would need to operate within to create what you want.

Anyway, how I would do it (and this is based on .net Membership being used out-of-the-box):

ASP.NET allows you attach 'roles' to users and 'profile' attributes to those users too. Profiles are used to attach things such as "Telephone Number" and other meta-data to users but you could just as well use it to attach their home 'subsite' to them as well.

I would create a role called 'globaladmin', create yourself as a user and then assign you (and only you) to that role. I would then create a 'siteadmin' role and assign each subsite's admin user to that role but being very careful to assign them a 'site' profile entry which has the value that corresponds to the site they are admin for.

For example, 'user123' would be assigned to the 'siteadmin' role and their 'site' profile attribute could be 'subsitexyz'. They would then be identified as the administrator for that site.

The above is workable but if you really want to make this as slick as possible, create your own MembershipProvider (SubsiteMembershipProvider) and create a new SubsiteMembershipUser class that inherits from MembershipUser that your new provider returns. You could then add your own properties to SubsiteMembershipUser that your app can query to find out which site the user belongs to:

//get current logged on user - cast it to our custom membership user object
SubsiteMembershipUser thisUser = (SubsiteMembershipUser)GetUser(); 
if(thisUser.SubsiteName == SiteUserIsBrowsingString
&& Roles.IsUserInRole(thisUser.UserName, "siteadmin"))
  //user is admin for this site so do something
Neil Trodden
Thanks Neil, your interpretation of 'SubSite' is exactly what I was trying to communicate. It's a concept difficult to google because so many pages use the term in different ways. Anyway, your post has been helpful. I hope others will expand on it or point out articles that apply. Thanks again!
Robert Claypool
np, it's fun to think of unusual ways to do things but I'd never have searched for multi-tenant app in a million years!
Neil Trodden
+3  A: 

What you're attempting is more commonly referred to as "multitenancy", not "subsites"

There was a similar question to this, and the accepted answer sounds plausible.

DSO
Awesome! This reminds me of http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/. Abelson (or was it Sussman?) talked about the importance of knowing the true name of a thing.
Robert Claypool
My first search for "ASP.Net Multitenancy" provided tons of info and examples. Thanks again.
Robert Claypool