Search code examples
c#asp.netado.netwindows-authentication

How to connect to SQL Server database in web using client windows credentials


Scenario: instead of using the server Windows credentials to connect to database, I want to use the Windows credentials from which the person is accessing website.

  • IIS hosted Server IP: : 10.10.10.10
  • Website Accessing from client machine : 10.10.10.11

I want to use the credentials from logged in user of 10.10.10.11 for accessing the database.

Is there any way to do that? I tried searching in google extensively and failed to get a proper answer. Please let me know how to achieve this or give me a lead so as to get this done.


Solution

  • Change the configuration to

    <configuration>
      <system.web>
        <authentication mode="Windows"/>
        <identity impersonate="true" />
      </system.web>
    </configuration>
    

    And Go to IIS Server >> Sites >> Website>> Authentication

    Anonymous Authentication >> Disabled
    ASP.Net Impersonation    >> Enabled
    Basic Authentication     >> Enabled
    Forms Authentication     >> Disabled
    Windows Authentication   >> Disabled
    

    This will generate a popup for credentials. When credentials are entered, it will be used to connect to the database.