User Context (cs-username) Not Logged in IIS log file After Migrating from .NET Framework to .NET 8 Web API

SSGANAPATHY 0 Reputation points
2025-04-28T16:08:56.4633333+00:00

After migrating .NET Framework Web API to .NET 8, you noticed that the user context (cs-username) is no longer being logged in the IIS log file.

In .NET Framework Web API, I'm using FormsAuthenticationTicket to set the user context in Global.asax Application_AuthenticateRequest event.

In .NET 8 Web API, I'm using JWT Token to set the user context in middleware.

IIS Version - 10

OS - Window Server 2022

HostingModel - inprocess

How do I log user context (cs-username) in IIS log file?

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,230 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 75,051 Reputation points
    2025-05-03T16:52:40.8966667+00:00

    Asp.net core does not use the old framework pipeline, so there is no access to user context. Instead asp.net core writes its own logs and iis saves them. You probably want to use the w3c logger format instead of the default.

    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/w3c-logger/?view=aspnetcore-9.0

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.