I´ve got a asp.net core application running on kestrel behind an IIS 7.5. I always use anonymous authentication configured in IIS to use one specific user from my active directory.
I´m unable to get Access to the sql server because i cant Access with anonymous Access. It returns and error related to the session user when the program Access to the sql server:
SqlException: Error de inicio de sesión del usuario 'Domain\machine name$'.
This error means that he cant loging into the sql server.
Whith asp.net i get this configuring the web.config but in Core is my first time to configure this.
I have seen the same solution in different places that is not working for me:
In startup.cs i define a middleware to invoke impersonation:
public classImpersonate
{
privatereadonlyRequestDelegate next;
public Impersonate(RequestDelegate next)
{
this.next = next;
}
publicasyncTask Invoke(HttpContext context)
{
var winIdent = context.User.Identity asWindowsIdentity;
if (winIdent == null)
{
await next.Invoke(context);
}
else
{
awaitWindowsIdentity.RunImpersonated(winIdent.AccessToken,async () => {await next.Invoke(context);
});
}
}
}
Finally in Configure method i call to the middleware before i call to the mvc:
app.UseMiddleware<Impersonate>();
Aditionally in web.config i set
forwardWindowsAuthToken="true"
Any help?