Link to home
Start Free TrialLog in
Avatar of CaptainGiblets
CaptainGibletsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Connecting to SQL via IIS using integrated authentication

I have a web server on my domain that i want to use to connect to an SQL database.

Ideally i want my users to log on to the web server using integrated authentication, then the web server pass the same details on to the SQL server so i can use the built in audit tools.

I have enabled  Windows authentication and ASP.net Impersonate in IIS

my web.config file has the below

  <system.web>
    <compilation targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" maxRequestLength="50000" /> <!-- 50mb -->
    <authentication mode="Windows"/>
  </system.web>

and

<connectionStrings>
 <add name="sitename" connectionString="Data Source=servername; Initial Catalog=databasename;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
  </connectionStrings>

We are running on port 8081 as this is a back end API, i have added an SPN of setspn -s http/hostname:8081 hostname  (unsure if i had to do this i thought i would try it but didnt make a difference)

we are using web API to return the login name (user.identity.name) which returns fine on a page that just returns the information but to connect to the SQL server we are using entity framework which uses the above connection string.

We have a test page using the indentity name and it returns all the details fine on local host and remote host however for the entity framework we get this message {"Message":"Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'."}

Is there an easy way to resolve this or an easier way to create a trusted SQL connection on an intranet enviornment.

Thanks in advance for any help provided.
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
{"Message":"Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'."}
Are you connecting to the test webpage with a valid domain user?