How to get Windows user credentials using forms authentication?

Our all libraries and application use forms authentication, so it is necessary to use it here.

The application is hosted on IIS with below settings:

  • anonymous authentication: enabled
  • forms authentication: enabled
  • windows authentication: disabled (this must not be changed)

    This returns the user under IIS runs (in my case IIS APPPOOL\tdm)

    string userName = System.Security.Principal.WindowsIdentity.GetCurrent();
    string userName = Environment.UserName;
    

    In web.config:

    <authentication mode="None" /> //(this again must not be changed)
    

    Is it possible somehow to take the Windows credentials of the user who uses the application? My job is when someone enters the app to log in with this credentials automatically, but for that, I must find a way to take his Windows user account.

    Upvotes: 2

    Views: 496

  • Answers (1)

    ste-fu
    ste-fu

    Reputation: 7434

    I don't think that what you are asking for is possible within a standard webforms framework. You cannot automatically get a browser to send the windows credentials without enabling windows authentication.

    If the application is hosted on the same domain, it is relatively easy to use standard forms authentication with an existing AD username/password - also called Single Sign On.

    When you enable Windows authentication in an application, and then make a request from a browser, it actually returns a 401 - Unauthorized status code. The browser then decides based on your settings whether to send your identity in a second request. This may happen automatically, or it may prompt for credentials.

    Upvotes: 3

    Related Questions