0

I have an asp.net 5 web application on .NET Framework 4.8 running as an azure app service with a windows server 2019 container image. I setup a diagnostic setting to send the 'AppServiceHTTPLogs' to an event hub and when inspecting the logs, I noticed that the CsUsername property is missing for authenticated requests.

Running the same container image locally or even as an Azure Container Instance and inspecting the IIS logs on the container I can see the username so it's something to do with how and where the https logs are captured when running as an app service where the logs don't pick up on the authenticated principal's identity name.

Has anybody else run into this? Do I need to expose the principal as a response header for the logging to pick it up?

UPDATE: 02/24/2022

In addition to asking here I had also started a case with azure support inquiring about why the web server logs from an azure app service on a windows app service plan running a windows container is missing the cs-username information whereas consoling the running container of the app service and inspecting the w3c log in C:\inetpub\logs\LogFiles\W3SVC1 shows the cs-username value.

They finally got back and said:

At this moment I'm afraid that this feature is not supported for the architecture that you have set, the only way to get the details for the CsUsername is to deploy a Linux App Service and then target an Azure Storage account as the data endpoint.

That doesn't help me at all since I can't run a .NET Framework 4.8 ASP.NET MVC 5 application container in a Linux app service plan. Generally, through this ordeal of deploying windows containers to run as an azure app service with an Azure DevOps pipeline to running the container as an azure app service, I've found microsoft's support for running windows based containers to be very challenging and without much ongoing support. They try to push the linux hosting environment which unfortunately is an option only if your architecture is based on the .NET core framework.

Huzaifa Tapal
  • 111
  • 1
  • 4

1 Answers1

0

Has anybody else run into this? Do I need to expose the principal as a response header for the logging to pick it up?

This issue could be resolved in 2 different ways below are the resolution steps

A] Change applicationHost.config directly

Edit the applicationHost.config file for the Advanced Logging feature using the following steps:

  • Open the C:\Windows\System32\inetsrv\config\applicationHost.config file in a text editor.
  • Locate the advancedLogging section.
  • In advancedLogging, locate the <field id='UserName'...> entry.

<field id="UserName" sourceName="UserName" sourceType="
 RequestHeader " logHeaderName="cs-username" category="Default" loggingDataType="TypeLPCSTR" />
  • Modify the sourceType field to be BuiltIn, as follows:

<field id="UserName" sourceName="UserName" sourceType="
 BuiltIn " logHeaderName="cs-username" category="Default" loggingDataType="TypeLPCSTR" />

B] Change applicationHost.config by Appcmd.exe

You can use the appcmd.exe tool to make the configuration changes .

Run this command :

appcmd.exe set config -section:system.webServer/advancedLogging/server
/fields.[id='UserName'].sourceType:"BuiltIn" /commit:apphost

For complete information you can go through the below mentioned links

No cs-username data in Advanced Logging - Internet Information Services | Microsoft Docs

cs-username not populated in IIS logs · Issue #6741 · dotnet/aspnetcore · GitHub

SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15
  • I looked in the C:\Windows\System32\inetsrv\config\applicationHost.config file in windows container and I don't see the section for advancedLogging. I'm using the 4.8-windowsservercore-ltsc2019 base image. Checking https://learn.microsoft.com/en-us/iis/extensions/advanced-logging-module/advanced-logging-for-iis-custom-logging it says that Advanced Logging is only supported for IIS 7.5 and earlier. Is that the reason? – Huzaifa Tapal Feb 23 '22 at 00:31
  • Also, when I console the app service container using Kudu and check the IIS logs in the container, I see the username. The app service abstraction seems to not be logging this information that is available in the IIS module in the container. – Huzaifa Tapal Feb 23 '22 at 00:39