Search code examples
asp.net-mvc-3razorwindows-authentication

MVC 3 Windows Authentication and Additional User Data


I am new to MVC3. I am seeking for suggestions to achieve below:

  1. My MVC3 Site is enabled for Windows Authentication.
  2. I have separate UserProfile table in the Oracle DB which will contain roles information.
  3. The user can have multiple products associated. For each product role(s) for user vary.

Need:

  1. As soon as user is authenticated, I want to fetch the application specific details from DB for currently selected product. I can do this by RoleProvider I guess.
  2. I want append this information to User object. How do I do this?
  3. If the user changes the product, I should be able reset the additional information to the User object. Is it possible? How can I do it?

Thanks Arun


Solution

  • You could use a Custom Principal and identity to attach additional data to your user. With a custom membership provider you can load the data from the database on authentication. When to product changes you can fetch the user from the current thread and you can call for example the method User.UpdateProducts() that you have written on the custom identity.

    Here is an Example

    Full blown example in VB