// <snippet2> private ICollection LoadControlProperties(string serializedProperties) { ICollection controlProperties = null; // Create an ObjectStateFormatter to deserialize the properties. ObjectStateFormatter formatter = new ObjectStateFormatter(); try { // Call the Deserialize method. controlProperties = (ArrayList)formatter.Deserialize(serializedProperties); } catch (HttpException e) { ViewStateException vse = (ViewStateException)e.InnerException; String logMessage; logMessage = "ViewStateException. Path: " + vse.Path + Environment.NewLine; logMessage += "PersistedState: " + vse.PersistedState + Environment.NewLine; logMessage += "Referer: " + vse.Referer + Environment.NewLine; logMessage += "UserAgent: " + vse.UserAgent + Environment.NewLine; LogEvent(logMessage); if (vse.IsConnected) { HttpContext.Current.Response.Redirect("ErrorPage.aspx"); } else { throw e; } } return(controlProperties); }
private void AddViewStateExceptionDataFields(ArrayList dataFields, ViewStateException vse) { dataFields.Add(System.Web.SR.GetString(vse.ShortMessage)); dataFields.Add(vse.RemoteAddress); dataFields.Add(vse.RemotePort); dataFields.Add(vse.UserAgent); dataFields.Add(vse.PersistedState); dataFields.Add(vse.Referer); dataFields.Add(vse.Path); }
private static void FindEventCode(Exception e, ref int eventCode, ref int eventDetailsCode, ref Exception eStack) { eventDetailsCode = 0; if (e is ConfigurationException) { eventCode = 0xbc0; } else if (e is HttpRequestValidationException) { eventCode = 0xbbb; } else if (e is HttpCompileException) { eventCode = 0xbbf; } else if (e is SecurityException) { eventCode = 0xfaa; } else if (e is UnauthorizedAccessException) { eventCode = 0xfab; } else if (e is HttpParseException) { eventCode = 0xbbe; } else if ((e is HttpException) && (e.InnerException is ViewStateException)) { ViewStateException innerException = (ViewStateException)e.InnerException; eventCode = 0xfa9; if (innerException._macValidationError) { eventDetailsCode = 0xc41b; } else { eventDetailsCode = 0xc41c; } eStack = innerException; } else if ((e is HttpException) && (((HttpException)e).WebEventCode != 0)) { eventCode = ((HttpException)e).WebEventCode; } else if (e.InnerException != null) { if (eStack == null) { eStack = e.InnerException; } FindEventCode(e.InnerException, ref eventCode, ref eventDetailsCode, ref eStack); } else { eventCode = 0xbbd; } if (eStack == null) { eStack = e; } }
public override void ProcessEvent(WebBaseEvent eventRaised) { UnsafeNativeMethods.WmiData wmiData = new UnsafeNativeMethods.WmiData(); this.FillBasicWmiDataFields(ref wmiData, eventRaised); WebApplicationLifetimeEvent event1 = eventRaised as WebApplicationLifetimeEvent; if (eventRaised is WebManagementEvent) { WebProcessInformation processInformation = ((WebManagementEvent)eventRaised).ProcessInformation; wmiData.processId = processInformation.ProcessID; wmiData.processName = processInformation.ProcessName; wmiData.accountName = processInformation.AccountName; } if (eventRaised is WebRequestEvent) { this.FillRequestWmiDataFields(ref wmiData, ((WebRequestEvent)eventRaised).RequestInformation); } if (eventRaised is WebAuditEvent) { this.FillRequestWmiDataFields(ref wmiData, ((WebAuditEvent)eventRaised).RequestInformation); } if (eventRaised is WebAuthenticationSuccessAuditEvent) { wmiData.nameToAuthenticate = ((WebAuthenticationSuccessAuditEvent)eventRaised).NameToAuthenticate; } if (eventRaised is WebAuthenticationFailureAuditEvent) { wmiData.nameToAuthenticate = ((WebAuthenticationFailureAuditEvent)eventRaised).NameToAuthenticate; } if (eventRaised is WebViewStateFailureAuditEvent) { ViewStateException viewStateException = ((WebViewStateFailureAuditEvent)eventRaised).ViewStateException; wmiData.exceptionMessage = System.Web.SR.GetString(viewStateException.ShortMessage); wmiData.remoteAddress = viewStateException.RemoteAddress; wmiData.remotePort = viewStateException.RemotePort; wmiData.userAgent = viewStateException.UserAgent; wmiData.persistedState = viewStateException.PersistedState; wmiData.referer = viewStateException.Referer; wmiData.path = viewStateException.Path; } if (eventRaised is WebHeartbeatEvent) { WebHeartbeatEvent event2 = eventRaised as WebHeartbeatEvent; WebProcessStatistics processStatistics = event2.ProcessStatistics; wmiData.processStartTime = this.WmiFormatTime(processStatistics.ProcessStartTime); wmiData.threadCount = processStatistics.ThreadCount; wmiData.workingSet = processStatistics.WorkingSet.ToString(CultureInfo.InstalledUICulture); wmiData.peakWorkingSet = processStatistics.PeakWorkingSet.ToString(CultureInfo.InstalledUICulture); wmiData.managedHeapSize = processStatistics.ManagedHeapSize.ToString(CultureInfo.InstalledUICulture); wmiData.appdomainCount = processStatistics.AppDomainCount; wmiData.requestsExecuting = processStatistics.RequestsExecuting; wmiData.requestsQueued = processStatistics.RequestsQueued; wmiData.requestsRejected = processStatistics.RequestsRejected; } if (eventRaised is WebBaseErrorEvent) { Exception errorException = ((WebBaseErrorEvent)eventRaised).ErrorException; if (errorException == null) { wmiData.exceptionType = string.Empty; wmiData.exceptionMessage = string.Empty; } else { wmiData.exceptionType = errorException.GetType().Name; wmiData.exceptionMessage = errorException.Message; } } if (eventRaised is WebRequestErrorEvent) { WebRequestErrorEvent event3 = eventRaised as WebRequestErrorEvent; WebRequestInformation requestInformation = event3.RequestInformation; WebThreadInformation threadInformation = event3.ThreadInformation; this.FillRequestWmiDataFields(ref wmiData, requestInformation); this.FillErrorWmiDataFields(ref wmiData, threadInformation); } if (eventRaised is WebErrorEvent) { WebErrorEvent event4 = eventRaised as WebErrorEvent; WebRequestInformation reqInfo = event4.RequestInformation; WebThreadInformation threadInfo = event4.ThreadInformation; this.FillRequestWmiDataFields(ref wmiData, reqInfo); this.FillErrorWmiDataFields(ref wmiData, threadInfo); } int num = UnsafeNativeMethods.RaiseWmiEvent(ref wmiData, AspCompatApplicationStep.IsInAspCompatMode); if (num != 0) { throw new HttpException(System.Web.SR.GetString("Wmi_provider_error", new object[] { "0x" + num.ToString("X8", CultureInfo.InstalledUICulture) })); } }
public override void ProcessEvent(WebBaseEvent eventRaised) { Debug.Trace("WmiWebEventProvider", "ProcessEvent: event=" + eventRaised.GetType().Name); UnsafeNativeMethods.WmiData wmiData = new UnsafeNativeMethods.WmiData(); // Note: WMI sint64 requires a string param FillBasicWmiDataFields(ref wmiData, eventRaised); if (eventRaised is WebApplicationLifetimeEvent) { // Nothing special for this class. } if (eventRaised is WebManagementEvent) { WebProcessInformation processEventInfo = ((WebManagementEvent)eventRaised).ProcessInformation; wmiData.processId = processEventInfo.ProcessID; wmiData.processName = processEventInfo.ProcessName; wmiData.accountName = processEventInfo.AccountName; } if (eventRaised is WebRequestEvent) { FillRequestWmiDataFields(ref wmiData, ((WebRequestEvent)eventRaised).RequestInformation); } if (eventRaised is WebAuditEvent) { FillRequestWmiDataFields(ref wmiData, ((WebAuditEvent)eventRaised).RequestInformation); } if (eventRaised is WebAuthenticationSuccessAuditEvent) { wmiData.nameToAuthenticate = ((WebAuthenticationSuccessAuditEvent)eventRaised).NameToAuthenticate; } if (eventRaised is WebAuthenticationFailureAuditEvent) { wmiData.nameToAuthenticate = ((WebAuthenticationFailureAuditEvent)eventRaised).NameToAuthenticate; } if (eventRaised is WebViewStateFailureAuditEvent) { ViewStateException vse = ((WebViewStateFailureAuditEvent)eventRaised).ViewStateException; wmiData.exceptionMessage = SR.GetString(vse.ShortMessage); wmiData.remoteAddress = vse.RemoteAddress; wmiData.remotePort = vse.RemotePort; wmiData.userAgent = vse.UserAgent; wmiData.persistedState = vse.PersistedState; wmiData.referer = vse.Referer; wmiData.path = vse.Path; } if (eventRaised is WebHeartbeatEvent) { #if DBG try { #endif WebHeartbeatEvent hbEvent = eventRaised as WebHeartbeatEvent; WebProcessStatistics procStats = hbEvent.ProcessStatistics; wmiData.processStartTime = WmiFormatTime(procStats.ProcessStartTime); wmiData.threadCount = procStats.ThreadCount; wmiData.workingSet = procStats.WorkingSet.ToString(CultureInfo.InstalledUICulture); wmiData.peakWorkingSet = procStats.PeakWorkingSet.ToString(CultureInfo.InstalledUICulture); wmiData.managedHeapSize = procStats.ManagedHeapSize.ToString(CultureInfo.InstalledUICulture); wmiData.appdomainCount = procStats.AppDomainCount; wmiData.requestsExecuting = procStats.RequestsExecuting; wmiData.requestsQueued = procStats.RequestsQueued; wmiData.requestsRejected = procStats.RequestsRejected; #if DBG } catch (Exception e) { Debug.Trace("WmiWebEventProvider", e.ToString()); throw; } #endif } if (eventRaised is WebBaseErrorEvent) { Exception exception = ((WebBaseErrorEvent)eventRaised).ErrorException; if (exception == null) { wmiData.exceptionType = String.Empty; wmiData.exceptionMessage = String.Empty; } else { wmiData.exceptionType = exception.GetType().Name; wmiData.exceptionMessage = exception.Message; } } if (eventRaised is WebRequestErrorEvent) { WebRequestErrorEvent reEvent = eventRaised as WebRequestErrorEvent; WebRequestInformation reqInfo = reEvent.RequestInformation; WebThreadInformation threadInfo = reEvent.ThreadInformation; FillRequestWmiDataFields(ref wmiData, reqInfo); FillErrorWmiDataFields(ref wmiData, threadInfo); } if (eventRaised is WebErrorEvent) { WebErrorEvent eEvent = eventRaised as WebErrorEvent; WebRequestInformation reqInfo = eEvent.RequestInformation; WebThreadInformation threadInfo = eEvent.ThreadInformation; FillRequestWmiDataFields(ref wmiData, reqInfo); FillErrorWmiDataFields(ref wmiData, threadInfo); } int hr = UnsafeNativeMethods.RaiseWmiEvent(ref wmiData, AspCompatApplicationStep.IsInAspCompatMode); if (hr != 0) { throw new HttpException(SR.GetString(SR.Wmi_provider_error, "0x" + hr.ToString("X8", CultureInfo.InstalledUICulture))); } }