private void InitRequestInformation() { if (this._requestInfo == null) { this._requestInfo = new WebRequestInformation(); } }
void AddWebRequestInformationDataFields(ArrayList dataFields, WebRequestInformation reqInfo) { string user; string authType; bool authed; IPrincipal iprincipal = reqInfo.Principal; if (iprincipal == null) { user = null; authed = false; authType = null; } else { IIdentity id = iprincipal.Identity; user = id.Name; authed = id.IsAuthenticated; authType = id.AuthenticationType; } dataFields.Add(HttpUtility.UrlDecode(reqInfo.RequestUrl)); dataFields.Add(reqInfo.RequestPath); dataFields.Add(reqInfo.UserHostAddress); dataFields.Add(user); dataFields.Add(authed.ToString()); dataFields.Add(authType); dataFields.Add(reqInfo.ThreadAccountName); }
void FillRequestWmiDataFields(ref UnsafeNativeMethods.WmiData wmiData, WebRequestInformation reqInfo) { string user; string authType; bool authed; IPrincipal iprincipal = reqInfo.Principal; if (iprincipal == null) { user = String.Empty; authType = String.Empty; authed = false; } else { IIdentity id = iprincipal.Identity; user = id.Name; authed = id.IsAuthenticated; authType = id.AuthenticationType; } wmiData.requestUrl = reqInfo.RequestUrl; wmiData.requestPath = reqInfo.RequestPath; wmiData.userHostAddress = reqInfo.UserHostAddress; wmiData.userName = user; wmiData.userAuthenticated = authed; wmiData.userAuthenticationType = authType; wmiData.requestThreadAccountName = reqInfo.ThreadAccountName; }
private void AddWebRequestInformationDataFields(ArrayList dataFields, WebRequestInformation reqInfo) { string name; string authenticationType; bool isAuthenticated; IPrincipal principal = reqInfo.Principal; if (principal == null) { name = null; isAuthenticated = false; authenticationType = null; } else { IIdentity identity = principal.Identity; name = identity.Name; isAuthenticated = identity.IsAuthenticated; authenticationType = identity.AuthenticationType; } dataFields.Add(HttpUtility.UrlDecode(reqInfo.RequestUrl)); dataFields.Add(reqInfo.RequestPath); dataFields.Add(reqInfo.UserHostAddress); dataFields.Add(name); dataFields.Add(isAuthenticated.ToString()); dataFields.Add(authenticationType); dataFields.Add(reqInfo.ThreadAccountName); }
void FillParams(SqlCommand sqlCommand, WebBaseEvent eventRaised) { Exception exception = null; WebRequestInformation reqInfo = null; string details = null; WebApplicationInformation appInfo = WebBaseEvent.ApplicationInformation; int n = 0; sqlCommand.Parameters[n++].Value = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture); // @EventId sqlCommand.Parameters[n++].Value = eventRaised.EventTimeUtc; // @EventTimeUtc sqlCommand.Parameters[n++].Value = eventRaised.EventTime; // @EventTime sqlCommand.Parameters[n++].Value = eventRaised.GetType().ToString(); // @EventType sqlCommand.Parameters[n++].Value = eventRaised.EventSequence; // @EventSequence sqlCommand.Parameters[n++].Value = eventRaised.EventOccurrence; // @EventOccurrence sqlCommand.Parameters[n++].Value = eventRaised.EventCode; // @EventCode sqlCommand.Parameters[n++].Value = eventRaised.EventDetailCode; // @EventDetailCode sqlCommand.Parameters[n++].Value = eventRaised.Message; // @Message sqlCommand.Parameters[n++].Value = appInfo.ApplicationPath; // @ApplicationPath sqlCommand.Parameters[n++].Value = appInfo.ApplicationVirtualPath; // @ApplicationVirtualPath sqlCommand.Parameters[n++].Value = appInfo.MachineName; // @MachineName // // @RequestUrl if (eventRaised is WebRequestEvent) { reqInfo = ((WebRequestEvent)eventRaised).RequestInformation; } else if (eventRaised is WebRequestErrorEvent) { reqInfo = ((WebRequestErrorEvent)eventRaised).RequestInformation; } else if (eventRaised is WebErrorEvent) { reqInfo = ((WebErrorEvent)eventRaised).RequestInformation; } else if (eventRaised is WebAuditEvent) { reqInfo = ((WebAuditEvent)eventRaised).RequestInformation; } sqlCommand.Parameters[n++].Value = (reqInfo != null) ? reqInfo.RequestUrl : Convert.DBNull; // @ExceptionType if (eventRaised is WebBaseErrorEvent) { exception = ((WebBaseErrorEvent)eventRaised).ErrorException; } sqlCommand.Parameters[n++].Value = (exception != null) ? exception.GetType().ToString() : Convert.DBNull; // @Details details = eventRaised.ToString(); if (_maxEventDetailsLength != NO_LIMIT && details.Length > _maxEventDetailsLength) { details = details.Substring(0, _maxEventDetailsLength); } sqlCommand.Parameters[n++].Value = details; }
private void FillParams(SqlCommand sqlCommand, WebBaseEvent eventRaised) { Exception errorException = null; WebRequestInformation requestInformation = null; string str = null; WebApplicationInformation applicationInformation = WebBaseEvent.ApplicationInformation; int num = 0; sqlCommand.Parameters[num++].Value = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture); sqlCommand.Parameters[num++].Value = eventRaised.EventTimeUtc; sqlCommand.Parameters[num++].Value = eventRaised.EventTime; sqlCommand.Parameters[num++].Value = eventRaised.GetType().ToString(); sqlCommand.Parameters[num++].Value = eventRaised.EventSequence; sqlCommand.Parameters[num++].Value = eventRaised.EventOccurrence; sqlCommand.Parameters[num++].Value = eventRaised.EventCode; sqlCommand.Parameters[num++].Value = eventRaised.EventDetailCode; sqlCommand.Parameters[num++].Value = eventRaised.Message; sqlCommand.Parameters[num++].Value = applicationInformation.ApplicationPath; sqlCommand.Parameters[num++].Value = applicationInformation.ApplicationVirtualPath; sqlCommand.Parameters[num++].Value = applicationInformation.MachineName; if (eventRaised is WebRequestEvent) { requestInformation = ((WebRequestEvent)eventRaised).RequestInformation; } else if (eventRaised is WebRequestErrorEvent) { requestInformation = ((WebRequestErrorEvent)eventRaised).RequestInformation; } else if (eventRaised is WebErrorEvent) { requestInformation = ((WebErrorEvent)eventRaised).RequestInformation; } else if (eventRaised is WebAuditEvent) { requestInformation = ((WebAuditEvent)eventRaised).RequestInformation; } sqlCommand.Parameters[num++].Value = (requestInformation != null) ? requestInformation.RequestUrl : Convert.DBNull; if (eventRaised is WebBaseErrorEvent) { errorException = ((WebBaseErrorEvent)eventRaised).ErrorException; } sqlCommand.Parameters[num++].Value = (errorException != null) ? errorException.GetType().ToString() : Convert.DBNull; str = eventRaised.ToString(); if ((this._maxEventDetailsLength != -1) && (str.Length > this._maxEventDetailsLength)) { str = str.Substring(0, this._maxEventDetailsLength); } sqlCommand.Parameters[num++].Value = str; }
/// <summary> /// Create a message source provider from the provided web request and optionally Uri /// </summary> /// <param name="requestInformation"></param> /// <param name="requestUri"></param> public WebRequestSourceProvider(WebRequestInformation requestInformation, Uri requestUri) { if (requestInformation == null) return; //by default try to use the logical path as the class & method. if ((requestUri != null) && (string.IsNullOrEmpty(requestUri.AbsolutePath) == false)) { string swappedPath = requestUri.AbsolutePath.Replace('.', '_'); //we can't handle inline periods because they'll cause a parsing problem. swappedPath = swappedPath.Replace('/', '.'); string reformatedPath = "Web Site" + (swappedPath.StartsWith(".") ? swappedPath : "." + swappedPath); ClassName = reformatedPath; } FileName = requestInformation.RequestPath; }
private static string GetRequestXml(WebRequestInformation requestInformation) { //make sure we actually have something. if (requestInformation == null) return null; XmlDocument requestXml = new XmlDocument(); XmlElement requestNode = requestXml.CreateElement("requestInformation"); requestXml.AppendChild(requestNode); if (string.IsNullOrEmpty(requestInformation.RequestUrl) == false) { XmlElement requestUrlNode = requestXml.CreateElement("requestUrl"); requestUrlNode.InnerText = requestInformation.RequestUrl; requestNode.AppendChild(requestUrlNode); } if (string.IsNullOrEmpty(requestInformation.RequestPath) == false) { XmlElement requestPathNode = requestXml.CreateElement("requestPath"); requestPathNode.InnerText = requestInformation.RequestPath; requestNode.AppendChild(requestPathNode); } if (string.IsNullOrEmpty(requestInformation.UserHostAddress) == false) { XmlElement userHostAddressNode = requestXml.CreateElement("userHostAddress"); userHostAddressNode.InnerText = requestInformation.UserHostAddress; requestNode.AppendChild(userHostAddressNode); } if (string.IsNullOrEmpty(requestInformation.ThreadAccountName) == false) { XmlElement threadAccountNameNode = requestXml.CreateElement("threadAccountName"); threadAccountNameNode.InnerText = requestInformation.ThreadAccountName; requestNode.AppendChild(threadAccountNameNode); } return requestXml.InnerXml; }
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) })); } }
private void FillRequestWmiDataFields(ref UnsafeNativeMethods.WmiData wmiData, WebRequestInformation reqInfo) { string name; string authenticationType; bool isAuthenticated; IPrincipal principal = reqInfo.Principal; if (principal == null) { name = string.Empty; authenticationType = string.Empty; isAuthenticated = false; } else { IIdentity identity = principal.Identity; name = identity.Name; isAuthenticated = identity.IsAuthenticated; authenticationType = identity.AuthenticationType; } wmiData.requestUrl = reqInfo.RequestUrl; wmiData.requestPath = reqInfo.RequestPath; wmiData.userHostAddress = reqInfo.UserHostAddress; wmiData.userName = name; wmiData.userAuthenticated = isAuthenticated; wmiData.userAuthenticationType = authenticationType; wmiData.requestThreadAccountName = reqInfo.ThreadAccountName; }
void InitRequestInformation() { if (_requestInfo == null) { _requestInfo = new WebRequestInformation(); } }
private static string GetRequestXml(WebRequestInformation requestInformation) { //make sure we actually have something. if (requestInformation == null) return null; XmlDocument requestXml = new XmlDocument(); XmlElement requestNode = requestXml.CreateElement("requestInformation"); requestXml.AppendChild(requestNode); var sessionId = HttpContext.Current.Items["LoupeSessionId"] as string; var agentSessionId = HttpContext.Current.Items["LoupeAgentSessionId"] as string; if (!string.IsNullOrEmpty(sessionId)) { XmlElement sessionIdNode = requestXml.CreateElement("sessionId"); sessionIdNode.InnerText = sessionId; requestNode.AppendChild(sessionIdNode); } if (!string.IsNullOrEmpty(agentSessionId)) { XmlElement agentSessionIdNode = requestXml.CreateElement("agentSessionId"); agentSessionIdNode.InnerText = agentSessionId; requestNode.AppendChild(agentSessionIdNode); } if (!string.IsNullOrEmpty(sessionId) && HttpContext.Current.Cache[sessionId] != null) { var clientDetails = HttpContext.Current.Cache[sessionId] as string; clientDetails = clientDetails.Substring(15, clientDetails.Length - 31); XmlElement clientDetailsNode = requestXml.CreateElement("clientDetails"); clientDetailsNode.InnerXml = clientDetails; requestNode.AppendChild(clientDetailsNode); } if (string.IsNullOrEmpty(requestInformation.RequestUrl) == false) { XmlElement requestUrlNode = requestXml.CreateElement("requestUrl"); requestUrlNode.InnerText = requestInformation.RequestUrl; requestNode.AppendChild(requestUrlNode); } if (string.IsNullOrEmpty(requestInformation.RequestPath) == false) { XmlElement requestPathNode = requestXml.CreateElement("requestPath"); requestPathNode.InnerText = requestInformation.RequestPath; requestNode.AppendChild(requestPathNode); } if (string.IsNullOrEmpty(requestInformation.UserHostAddress) == false) { XmlElement userHostAddressNode = requestXml.CreateElement("userHostAddress"); userHostAddressNode.InnerText = requestInformation.UserHostAddress; requestNode.AppendChild(userHostAddressNode); } if (string.IsNullOrEmpty(requestInformation.ThreadAccountName) == false) { XmlElement threadAccountNameNode = requestXml.CreateElement("threadAccountName"); threadAccountNameNode.InnerText = requestInformation.ThreadAccountName; requestNode.AppendChild(threadAccountNameNode); } return requestXml.InnerXml; }
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))); } }