Reputation: 61
I have developed one MVC application and hosted in server. I used Service Account as app pool identity and provided full access(SysAdmin) on database to that Service Account only. Below are my configurations in Web.config & coding.
Web.config:
<authentication mode="Windows" />
<identity impersonate="false"/>
In my Data Access layer I'm using below coding to get windows identity :
string windowsLogin = HttpContext.Current.User.Identity.Name.ToString();
Now my issue is, when I'm accessing my application it is taking app pool Identity instead of Windows identity.
if I set the identity in Web.config to impersonate="true" I'm able to get windows login but the communication between application and database happening with my windows login instead of app pool identity (service account).
How can I get the identity of the user accessing the application and not the IIS APPPOOL user?
Upvotes: 4
Views: 4338
Reputation: 61
My Issue got resolved with below settings.
Created app pool and run it as with service account and configure it to web site in IIS.
In My Code File:
string windowsLogin = HttpContext.Current.Request.ServerVariables["LOGON_USER"].ToString();
In Web.config file:
<authentication mode="Windows">
</authentication>
<authorization>
<deny users="?" />
</authorization>
<identity impersonate="false" />
Note: It will give you an error if you run from Visual Studio IDE. If you publish and run it from IIS it will work.
Upvotes: 2