Skip to content

Possible bug in Microsoft.AspNet.WebApi 5.2.5 and onwards: HttpContext.Current.User is no longer available during the LogRequest event of HttpApplication #177

Closed
@stanisls

Description

@stanisls

This problem was discovered when using SerilogWeb.Classic UserName enricher. When ApplicationLifecycle module emits the final log entry for a request, the user name of the authenticated user is no longer captured by the UserName enricher.

It looks like HttpContext.Current.User.Identity.IsAuthenticated becomes 'false' by that point in time.
https://github.com/serilog-web/classic/blob/master/src/SerilogWeb.Classic/Classic/Enrichers/UserNameEnricher.cs

The problem first appered after updating to Microsoft.AspNet.WebApi 5.2.5 and is still in 5.2.6. The following screenshot of the logged data illustrates the problem. The only change between the 3 runs was a bump in versions of the Microsoft.AspNet.WebApi.* nuget packages.
webapibug

For more information, see a related bug report at SerilogWeb.Classic project:
serilog-web/classic#55

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions