sql-serverrazorasp.net-mvc-5user-accountsapplicationpoolidentity

MVC: how to print account trying to login to SQL database when using app pool identity specific account


I can print

System.Security.Principal.WindowsIdentity.GetCurrent().Name is @System.Security.Principal.WindowsIdentity.GetCurrent().Name

in a razor (.cshtml) file, however, I do not know how to print the app pool or verify that it is indeed accessing the database to login to it (as the login currently fails, that portion is an even tougher question).

This may require creating a string in the controller action trying to access the database, e.g. near something like:

db.myTable // etc

Thanks in advance.


Solution

  • The name you are returning in the code sample is the windows user id that the app pool is using (look in the app pool properties to see what windows username it is using).

    This user name, complete with domain name, needs to have access to the db.

    You may like to create your own windows user just for the app pool to use something other than local service as it may not be a good idea to give any local service access to your database.

    As Will says in his comment, sql profiler should be able to help you find out what's happening if you are not sure.