Aspnet core deployment to IIS - HTTP Error 502.3

2.6k Views Asked by At

I have created the IIS site and pointed it at the deployment folder. I have enabled stdout logging and this is the error:

info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0] User profile is available. Using 'C:\Users\No Managed Code\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. fail: Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler[1] An exception occurred in the database while iterating the results of a query. System.Data.SqlClient.SqlException: Cannot open database "KeyStoneDb" requested by the login. The login failed. Login failed for user 'IIS APPPOOL\No Managed Code'.

So, I added the login to SQL with all the necessary rights. Retested in DEV - fine, but when running IIS I still get the issue. The Application Pool being used is 'No Managed Code'.

Why cant the app not connect to the database?

1

There are 1 best solutions below

5
On

IIS AppPool accounts are virtual accounts, therefore, they don't actually exist as a normal user on the system.

You can not give access to networked resources using that identity. Shared\network resources like file shares and databases that need to communicate with these accounts need to have the 'domain\machinename$' with appropriate permissions.

Give 'domain\machinename$' appropriate permissions on your DB. That should do it.