How to get EventLog to write username in Windows event log?

I am writing a Windows event log using C #. I can set each field that is visible in the mmc.exe Computer Management tool, with the exception of the User field.

The client application is ASP.NET and uses forms authentication.

public static void WriteOnce()
{
    EventLog log = new EventLog("MyApp");
    if (!EventLog.SourceExists("MySource"))
    {
        EventSourceCreationData data = new EventSourceCreationData("MySource", "MyApp");
        EventLog.CreateEventSource(data);
    }
    log.Source = "MySource";
    log.WriteEntry("Hello World", EventLogEntryType.Information,123,456,new byte[]{1,2,3});
}

UPDATE: I checked in ASP.NET, even if the set identifier imersonation = true and authentication = windows and still no user.

I also checked in the user console application.

+5
source share
4 answers

, , , , , . , pinvoke/native .

http://www.infosysblogs.com/microsoft/2007/09/logging_events_with_user_detai_1.html

ASPNET NETWORK SERVICES . api SID. , .

JPucket , , , - .

0

, - , AppDomain. , Windows "" .

+2

, . . ASP.NET, .

EDIT: I found a similar question . He suggests using the Win32 Api ReportEvent function to set user information.

+2
source

System.DiagnosticsAllows your ASP.NET application to access the Windows event log directly. Since your application is an ASP.NET application, you can use

HttpContext.Current.User.Identity.Name

to get the current username (in this case there will be an Auth form token, since you use forms authentication).

+1
source

All Articles