Matt Roberts
Matt Roberts

Reputation: 26917

cs-username (username) from IIS logs in azure

I've got a "classic" asp.net web app hosted on azure as an app service, with web server logs enabled. My logs include a handy cs-username property, which is the username of the logged in user (using asp.net identity).

I've also got an asp.net core web app, that uses identity in a similar way to authenticate users. But in the IIS logs for that, I don't get a cs-username. Can anyone tell if it's possible to get that in asp.net core?

Upvotes: 0

Views: 1311

Answers (1)

Muqeet Khan
Muqeet Khan

Reputation: 2134

I am pretty certain if you use windows authentication in aspnet core application you will populate cs-username. Having said that, please don’t use integrated windows authentication. In classic asp apps, it was an ISAPI filter within the IIS processing pipeline. Therefore, IIS had access to that information and could log it. That’s not the case with ASP.Net core applications. Aspnet core uses its own web server called kestrel and IIS just acts as a proxy. Technically, IIS has no idea of what is going on with that request\response. It just receives requests and serves up the response to the requestor. That’s all.

If you want to get the user information from aspnet core strictly from logs then you want to enable the Aspnetcore module logs using your web.config. You will need to give it a directory to write the logs though which I don’t know how that works on azure.

Because you are on azure your best bet is to turn on application insights and gather all your information from there. Aspnet core does excellent logs. You can also use log collectors like serilog and then do your own thing to collect and store logs in sql server or files or whereever. Look into serilog and sinks if you want to go that route.

Upvotes: 1

Related Questions