2
votes

For an ASP.NET application, how can I prompt the user for their username / password when Integrated Windows Authentication is used? I would like to use C# in the code behind of the pages to do this.

I want some pages (e.g. http://intranet/admin/) to prompt for a password, while others automatically go though (via IWA/NTLM). I would then like it to remember that the user has logged in as they visit other pages in the folder / site and offer a logout link for when they are finished.

Edit: What I want to do is send a 401 status and WWW-Authentication headers to the user, so they then log in using their Windows Credentials.

Basically, how Firefox / IE do it if the site isn't trusted.

Edit 2: SharePoint does this kind of thing, where you automatically log in, but can log out and log in as someone else without needing to log out of Windows.

Edit 3:

An example (other than SharePoint): You are logged in as a standard (limited access) Windows / Active Directory user to a trusted site, which passes on your credentials. You then want to log into an admin part of the site with different credentials (but still Windows, not WebForms). The only other way of doing it is if you log off Windows, then log in again. Not practical if you have files open (that you may wish to access) or the administrator can't log in locally (Interactive Login Privilege disabled). Impersonation may be set, as the page allows access to applications the regular user account doesn't (e.g. databases, files, Active Directory admin).

Basically making a page within the site behave as though it is not part of the Trusted Sites zone.

2

2 Answers

2
votes

Sounds like you need to use Impersonation. This allows you to "run as" another Windows user. See here: ASP.NET Impersonation

Here are a couple CodeProject examples:

Windows Impersonation using C#

User Impersonation in .NET

-1
votes

No seperate code for this.

When the user/client open the particular pate eg., http://intranet/admin/index.aspx

if you configure the particular folder with windows authentication, the browser will

automatically ask for the username and password of the particular user/client.

so this is the configuration that you have to do in the IIS to the particular folder

to which you would like to apply the integrated windows authentication.