I have an ASP.NET MVC3 application that uses Windows Authentication and the SqlRoleManager provider. I am trying to connect to a database with integrated security. The database team is requiring that each user be authorized to use the database using Windows authentication rather than a simple user name and password that can be used for the web application. I used the code below and found out that the principal is actually the app pool user. How do I attach the session to the current windows user? Is that even possible?
WindowsIdentity identity = WindowsIdentity.GetCurrent();
Response.Write(identity.Name);
Some things to try:
Similar to this question .
Excerpt from MSDN Article :
The Context.User.Identity.Name property returns the authenticated user's identity. When the application runs in IIS 7, and impersonation is disabled, the Environment.UserName property returns the identity of the application pool that the Web application is running in. For example, if the Web site is running in the default application pool, the name DefaultAppPool is displayed. If the ASP.NET v4.0 application pool is used, ASP.NET v4.0 is displayed.
We have a post on msdn regarding this
http://msdn.microsoft.com/en-us/library/bsz5788z(v=vs.100).aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.