views:

45

answers:

2

I've got a small problem with my app design and MVC membership.

In my site I have 3 tables: users, customers and authors, none of them are related to one another but each of them is connected to a bunch of other tables so I cannot really combine them into one big users table.

I'm not sure how to implement the all membership, authorization stuff since I've got three login forms, one for each DB entity and when calling User.Identity.IsAuthenticated I won't be able to tell who is logged in.

Any ideas?

A: 

My recommendation is that you move to a single user table. Just add a field to the users table that determines the type of user (Customer, Author, etc). No need to combine all the tables into one.

Brian
+1  A: 

Sounds like a case for Role-Based Authorization, and if you're using the built in ASP.NET Membership provider, it's fairly simple.

Create a role for Users, Customers, Authors.

Then you can do this:

if (User.Identity.IsAuthenticated)
{
   if (User.IsUserInRole("Customer")
      ...
   else if (User.IsUserInRole("Author")
      ...
}

Here's an article with a brief overview.

That being said though, re-think your design for having those 3 tables.

You could easily have one table with all the users. This table doesn't need to care about "what type of user" each record is, this is handled by the ASP.NET Membership provider.

RPM1984

related questions