EIF events that are raised from an ASP.NET page do not succeed when the impersonation feature is turned on (839990)
The information in this article applies to:
- Microsoft Enterprise Instrumentation Framework
SYMPTOMSWhen you raise Microsoft Enterprise Instrumentation Framework (EIF) events to a trace session from a Microsoft ASP.NET page, the following exception may be logged in the application event log:
Error loading an Event Sink of type Microsoft.EnterpriseInstrumentation.EventSinks.TraceEventSink'. The Event Source of name 'Application' will not write events out to this Event Sink. The following exception was returned during the load:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
--->System.ComponentModel.Win32Exception: Unable to register with the Windows Trace Event Session TraceSession. Tracing is disabled to this session. When calling the RegisterTraceGuids() API an error code of 5 and message "Access is denied" was returned.
at Microsoft.EnterpriseInstrumentation.EventSinks.TraceEventSink..ctor(IDictionary parameters, EventSource eventSource)
--- End of inner exception stack trace ---
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Microsoft.EnterpriseInstrumentation.EventSinks.EventSink.CreateNewEventSinks(DataRow[] eventSinkRows, EventSource eventSource)CAUSEThe RegisterTraceGuids() API is used to register the event trace provider and the trace classes that are required to raise the events to the trace sessions. When the TraceEventSink event sink is created, a call to the RegisterTraceGuids() API does not succeed, and you receive an "Access Denied" error message. The call does not succeed because the ASPX page is impersonating a thread identity that does not have sufficient permissions to access a process handle for registration.
RESOLUTIONTo resolve this problem, use one of the following methods: - Raise the first EIF event in the context of the process identity. You must raise the first EIF event on the .aspx page that raises the first event. To do this:
- Revert to the process identity.
- Raise the EIF event.
- Restore the thread identity.
- Implement the revert and restore process in the Application_Start method in the Global.Asax page.
You only have to perform this step one time during the application lifetime.
Implement the revert and restore processThe following sample code for Microsoft Visual C# .NET and Microsoft Visual Basic .NET demonstrates how to perform the revert and restore process. This process raises the first EIF event in the ASP.NET application.
Visual C# .NET
using System.Security.Principal;
WindowsImpersonationContext context = null;
try
{
// Revert to process identity.
context = WindowsIdentity.Impersonate(IntPtr.Zero);
// Raise the first EIF event of the application.
TraceMessageEvent.Raise("Trace Message Event from Webform1.aspx");
}
catch (Exception ex)
{
Response.Write("Exception Thrown. !Error Message: {0}", ex.Message.ToString());
}
finally
{
// Restore the thread's identity.
if (context != null)
context.Undo();
}
Visual Basic .NET
Imports System.Security.Principal
Dim context as WindowsImpersonationContext
Try
'Revert to process identity.
context = WindowsIdentity.Impersonate(IntPtr.Zero)
'Raise the first EIF event of the application.
TraceMessageEvent.Raise("Trace Message Event From Webform1.aspx")
Catch ex as Exception
Response.Write("ExceptionThrown!. Error Message: " & ex.Message.ToString())
Finally
'Restore thread identity.
if (Not ( IsNothing(context))) Then
context.undo
End If
End Try
STATUS
This behavior is by design.REFERENCESFor more information about how to use the Microsoft Enterprise Instrumentation Framework, visit the following Microsoft Developer Network (MSDN) Web site:
Modification Type: | Major | Last Reviewed: | 6/21/2004 |
---|
Keywords: | kbprb KB839990 kbAudDeveloper |
---|
|