.NET Programming
--
Questions
--
Followers
Top Experts
.Net Core - Impersonation Help!
Hello EE Community,
I have been struggling trying to figure out how the heck to impersonate via .Net Core API sending a HttpWebRequest as the Windows Identity user. I have tried forum articles out there and posting what I tried last but this does not work. It works fine when I run via IIS Express I have Windows Authentication and Anonymous on that I need for now. When I run via IIS Express the "DefaultCredentials" are picking up my credentials but when I run deployed to IIS the Application Pool identity is using a service account which I understand but now I need to impersonate and with Core it seems so difficult. This is what I am trying when deploying to IIS but it is not working and still picking up the app pool identity service account versus my Windows Identity essentially. The Windows Identity has myself correct but the DefaultCredentials does not it uses the app pool. I tried this via forum articles still no dice the CredentialCache.DefaultCre dentials is still the app pool. Needing help understanding how to handle this in Core.
I have been struggling trying to figure out how the heck to impersonate via .Net Core API sending a HttpWebRequest as the Windows Identity user. I have tried forum articles out there and posting what I tried last but this does not work. It works fine when I run via IIS Express I have Windows Authentication and Anonymous on that I need for now. When I run via IIS Express the "DefaultCredentials" are picking up my credentials but when I run deployed to IIS the Application Pool identity is using a service account which I understand but now I need to impersonate and with Core it seems so difficult. This is what I am trying when deploying to IIS but it is not working and still picking up the app pool identity service account versus my Windows Identity essentially. The Windows Identity has myself correct but the DefaultCredentials does not it uses the app pool. I tried this via forum articles still no dice the CredentialCache.DefaultCre
WindowsIdentity identity = (WindowsIdentity)_httpContextAccessor.HttpContext.User.Identity;
WindowsIdentity.RunImpersonated(identity.AccessToken, () =>
{
Uri theUri = new Uri(string.Concat(this.session.HostURL, "/refi/services"));
HttpWebRequest theHttpWebRequest = (HttpWebRequest)WebRequest.Create(theUri);
theHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;
theHttpWebRequest.Timeout = 210000;
theHttpWebRequest.CookieContainer = session.CookieContainer;
HttpWebResponse theHttpWebResponse = (HttpWebResponse)theHttpWebRequest.GetResponse();
theHttpWebResponse.Close();
});
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Hi Sean,
I am doing some guess work here but did you try using DefaultNetworkCredentials instead of DefaultCredentials?
Regards,
Chinmay.
No that did not work but thanks for the idea.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
.NET Programming
--
Questions
--
Followers
Top Experts
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
Create your account and start contributing!