Search code examples
c#asp.netasp.net-mvc-3windows-authentication

Asp.net mvc 3 Windows Authentication with Login form


I have already created a form authentication application. I had User table and created a custom membership provider. My user table has relations with other tables such as roles and permissions.

  1. I change that to work using Windows Authentication. It looks easy but I have no clue how to still be able to read permissions from my tables? some tables are related to User table and requires user id, what to do here? should I break the foreign key?

  2. If a user is accessing the page from LAN, s/he should get logged automatically, but if they accessed the application over internet, I should allow them to login? How to do this? What passwords should they use to login (active directory or my User table)?

I hope i get simple and easy answers.

Regards


Solution

    1. In your controllers you can use User.Identity.Name to get the users AD username. You can then add a field to your users table called ADUSername (or update the values in the existing username field) so that you can link the logged in user to the existing user record in your database.

    2. You don't have to do anything, if the user is accessing it from an external network or any machine that is not on the domain the browser will pop up a username/password prompt.