Click here to Skip to main content
15,441,280 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am connecting to a web API via windows authentication. The native method of this API uses
CredentialCache.DefaultCredentials
to authenticate users in their application. Now I have developed a booking website to use the API data and write it back into the application. I want to authenticate the users through my website but I can't get it to work. I always authenticate with the user running the IIS AppPool of the website.

What I have tried:

The website is aspx and
C#
Page.User.Identity.Name
returns the domain and user who is visiting it. I tried impersonating the request with the current user client side. I use windows authentication as authentication method at the IIS.

WindowsImpersonationContext impersonationContext;
               using (impersonationContext = ((WindowsIdentity)Page.User.Identity).Impersonate())
               {
                   conn = ServiceConnection.CreateWithWindowsAuthentication(new Uri("http://myWebsite"), CredentialCache.DefaultCredentials);
               }
               impersonationContext.Undo();


I turned off the Impersonation on IIS side because it won't load the page due to integraded pipeline mode which I can't turn off because the application needs to access local configuration files. For now I didn't manage to change the impersonated user or manage to get the IIdentity being used for my ICredentials.

Edit: I activated impersonation mode and assigned the web app to an AppPool with classic mode but still the result is the same.
Posted
Updated 11-Jun-19 4:05am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900