Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the logged in Windows domain account from an ASP.NET application?

We have an ASP.NET application that manages it's own User, Roles and Permission database and we have recently added a field to the User table to hold the Windows domain account.

I would like to make it so that the user doesn't have to physically log in to our application, but rather would be automatically logged in based on the currently logged in Windows domain account DOMAIN\username. We want to authenticate the Windows domain account against our own User table.

This is a piece of cake to do in Windows Forms, is it possible to do this in Web Forms?

I don't want the user to be prompted with a Windows challenge screen, I want our system to handle the log in.

Clarification: We are using our own custom Principal object.

Clarification: Not sure if it makes a difference or not, but we are using IIS7.

like image 725
mattruma Avatar asked Sep 10 '08 13:09

mattruma


People also ask

What gives domain username of the current user of the local machine?

Type whoami and press Enter. Your current user name will be displayed.

What is a Windows domain login?

A domain user is one whose username and password are stored on a domain controller rather than the computer the user is logging into. When you log in as a domain user, the computer asks the domain controller what privileges are assigned to you.

What account does ASP.NET run under?

The base identity for the ASP.NET ISAPI extension is set to the account of IIS (SYSTEM) and is not configurable. The base identity for the ASP.NET worker process by default is ASPNET, but you can change it to any other system- or user-defined account (including SYSTEM).


1 Answers

Integration of this sort is at the server level, it's IIS that decides that the user is not logged in; and it's IIS that sends back the authentication prompt to the user, to which the browser reacts.

As you want to use the domain login there is only one way to do this; integrated windows authentication. This will only work if the IIS server is also part of the domain and the users are accessing the machine directly, not through a proxy, and from machines which are also part of the domain (with the users suitably logged in).

However your custom principal object may create fun and games; authentication of this type will be a WindowsPrincipal and a WindowsIdentity; which you can access via the User object (see How To: Use Windows Authentication in ASP.NET 2.0)

I assume you want a custom principal because of your custom roles? I doubt you can get the two to play nicely; you could create a custom role provider which looks at your data store or look at you could look at ADAM, an extension to AD which provides roles on a per program basis and comes with nice management tools.

like image 148
blowdart Avatar answered Oct 15 '22 15:10

blowdart