Automatic login for authenticated MVC Forms application based on Windows username, perhaps?

I have an asp.net mvc application using forms authentication, i.e. users / passwords are in the database. This application is used by several clients on their servers and everyone would like their employees to register automatically according to the Intranet because apparently they could not use it to log in!?!

I'm sure you can't mix Windows and Forms authentication, so my question was, is there anyway windows / adobe username authentication or something so that I can authenticate them manually? I don't need to actually authenticate them through windows. I just need to somehow get information that will allow me to map them to a record in the database.

+3


source to share


1 answer


I did something similar to this. You need to configure IIS to activate Windows Authentication. If their AD account matches their ID for the web application (or simply adds a column for AD ID to the forms authentication database), you can remove the domain from your username and then validate it against your authentication database.

I have an HR database that we use to track employees and their titles, based on the data contained in this database, we allow certain privileges throughout the application:

Our company is still in the 2003 active directory, so it is impossible to manage credentials without finding a creative solution.



Here's my code: // find out who the Active Directory user is var username = Convert.ToString (User.Identity.Name);

    // strip the domain
    username = Regex.Replace(username, "DOMAIN", "");
    username = Regex.Replace(username, "\\\\", "");


    var first_initial = username[0];
    var last_initial = username[1];
    //The Ative directory structure is [first initial firstname][first inital lastname][badge number]
    var EIN = Regex.Replace(username, "[^0-9]", "");//get the badge number so we can query the badging database


    // check the employee database to see if this AD account matches something 
    var query = "SELECT BadgeNumber, FirstName, LastName,  DEPT_NUM, DEPT, TITLE, Supervisor " +
                     "FROM TABLE_WITH EMPLOYEE INFORMATION " +
                     "WHERE LEFT(FirstName, 1) = '" + first_initial + "' AND LEFT(LastName, 1) = '" + last_initial + "' AND BadgeNumber = '" + EIN + "' AND STATUS = 'Active' ";

      

0


source







All Articles