/// <summary> /// process a raised event /// </summary> /// <param name="eventRaised">the event to be processed</param> public override void ProcessEvent(WebBaseEvent eventRaised) { if (eventRaised == null) { throw new ArgumentNullException("eventRaised"); } if (UseBuffering) { base.ProcessEvent(eventRaised); } else { string extraInfo = string.Empty; WebBaseErrorEvent errorEvent = eventRaised as WebBaseErrorEvent; if (errorEvent != null) { extraInfo = errorEvent.ErrorException.ToString(); } this.customInfo.AppendLine( string.Format( CultureInfo.InvariantCulture, "Event Time (UTC):[{0}] Event Code:[{1}] Event Id:[{2}] Event Message:[{3}]", eventRaised.EventTimeUtc, eventRaised.EventCode, eventRaised.EventID, eventRaised.Message + " " + extraInfo)); this.StoreToFile(FileMode.Append); } }
internal static void EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) { if (!_theApplicationFactory._appOnStartCalled) { Exception innerException = null; lock (_theApplicationFactory) { if (!_theApplicationFactory._appOnStartCalled) { using (new DisposableHttpContextWrapper(context)) { WebBaseEvent.RaiseSystemEvent(_theApplicationFactory, 0x3e9); if (_theApplicationFactory._onStartMethod != null) { app.ProcessSpecialRequest(context, _theApplicationFactory._onStartMethod, _theApplicationFactory._onStartParamCount, _theApplicationFactory, EventArgs.Empty, null); } } } _theApplicationFactory._appOnStartCalled = true; innerException = context.Error; } if (innerException != null) { throw new HttpException(innerException.Message, innerException); } } }
private void OnEnter(object source, EventArgs eventArgs) { HttpApplication application = (HttpApplication)source; HttpContext context = application.Context; if (context.SkipAuthorization) { if ((context.User == null) || !context.User.Identity.IsAuthenticated) { PerfCounters.IncrementCounter(AppPerfCounter.ANONYMOUS_REQUESTS); } } else { AuthorizationSection authorization = RuntimeConfig.GetConfig(context).Authorization; if (!authorization.EveryoneAllowed && !authorization.IsUserAllowed(context.User, context.Request.RequestType)) { ReportUrlAuthorizationFailure(context, this); } else { if ((context.User == null) || !context.User.Identity.IsAuthenticated) { PerfCounters.IncrementCounter(AppPerfCounter.ANONYMOUS_REQUESTS); } WebBaseEvent.RaiseSystemEvent(this, 0xfa3); } } }
internal static void EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) { if (!_theApplicationFactory._appOnStartCalled) { Exception error = null; lock (_theApplicationFactory) { if (!_theApplicationFactory._appOnStartCalled) { using (new DisposableHttpContextWrapper(context)) { // impersonation could be required (UNC share or app credentials) WebBaseEvent.RaiseSystemEvent(_theApplicationFactory, WebEventCodes.ApplicationStart); if (_theApplicationFactory._onStartMethod != null) { app.ProcessSpecialRequest(context, _theApplicationFactory._onStartMethod, _theApplicationFactory._onStartParamCount, _theApplicationFactory, EventArgs.Empty, null); } } } _theApplicationFactory._appOnStartCalled = true; error = context.Error; } if (error != null) { throw new HttpException(error.Message, error); } } }
private Type DeserializeType(SerializerBinaryReader reader) { byte num = reader.ReadByte(); if (num == 0x2b) { int num2 = reader.ReadEncodedInt32(); return((Type)this._typeList[num2]); } string name = reader.ReadString(); Type type = null; try { if (num == 0x2a) { type = HttpContext.SystemWebAssembly.GetType(name, true); } else { type = Type.GetType(name, true); } } catch (Exception exception) { if (this._throwOnErrorDeserializing) { throw; } WebBaseEvent.RaiseSystemEvent(System.Web.SR.GetString("Webevent_msg_OSF_Deserialization_Type", new object[] { name }), this, 0xbc3, 0, exception); } this.AddDeserializationTypeReference(type); return(type); }
//public string RequestUrl { get; set; } public static WebEvent FromWebBaseEvent(WebBaseEvent webBaseEvent) { var webEvent = new WebEvent(); webEvent.ApplicationPath = HostingEnvironment.ApplicationPhysicalPath; webEvent.ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath; webEvent.Details = webBaseEvent.ToString(); webEvent.EventCode = webBaseEvent.EventCode; webEvent.EventDetailCode = webBaseEvent.EventDetailCode; webEvent.EventID = webBaseEvent.EventID; webEvent.EventOccurrence = webBaseEvent.EventOccurrence; webEvent.EventSequence = webBaseEvent.EventSequence; webEvent.EventTime = webBaseEvent.EventTime; webEvent.EventTimeUtc = webBaseEvent.EventTimeUtc; webEvent.EventType = webBaseEvent.GetType().Name; //webEvent.MachineName = HttpContext.Current.Server.MachineName; webEvent.Message = webBaseEvent.Message; //webEvent.RequestUrl = HttpContext.Current.Request.Url.ToString(); if (webBaseEvent is WebBaseErrorEvent) { webEvent.ExceptionType = ((WebBaseErrorEvent)webBaseEvent).ErrorException.GetType().Name; } return(webEvent); }
public override void ProcessEvent(WebBaseEvent raisedEvent) { var repo = DependencyResolver.Current.GetService <IService <Log> >(); var applicationInformation = WebBaseEvent.ApplicationInformation; var log = new Log { EventCode = raisedEvent.EventCode, EventType = raisedEvent.GetType().ToString(), EventSequence = raisedEvent.EventSequence, EventOccurrence = raisedEvent.EventOccurrence, Message = raisedEvent.Message, EventDetailCode = raisedEvent.EventDetailCode, ApplicationPath = applicationInformation.ApplicationPath, ApplicationVirtualPath = applicationInformation.ApplicationVirtualPath, MachineName = applicationInformation.MachineName }; if (raisedEvent is IUserInfoEvent) { log.Username = (raisedEvent as IUserInfoEvent).Username; log.Tenant = (raisedEvent as IUserInfoEvent).Tenant; } repo.SaveOrUpdate(log); }
//////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// // Module Enter: Get the authorization configuration section // and see if this user is allowed or not void OnEnter(Object source, EventArgs eventArgs) { HttpApplication app; HttpContext context; app = (HttpApplication)source; context = app.Context; if (context.SkipAuthorization) { if (context.User == null || !context.User.Identity.IsAuthenticated) { PerfCounters.IncrementCounter(AppPerfCounter.ANONYMOUS_REQUESTS); } return; } // Get the authorization config object AuthorizationSection settings = RuntimeConfig.GetConfig(context).Authorization; // Check if the user is allowed, or the request is for the login page if (!settings.EveryoneAllowed && !settings.IsUserAllowed(context.User, context.Request.RequestType)) { ReportUrlAuthorizationFailure(context, this); } else { if (context.User == null || !context.User.Identity.IsAuthenticated) { PerfCounters.IncrementCounter(AppPerfCounter.ANONYMOUS_REQUESTS); } WebBaseEvent.RaiseSystemEvent(this, WebEventCodes.AuditUrlAuthorizationSuccess); } }
public static void OnCacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason) { CacheItemUpdateReason updateReason; SentinelEntry entry = value as SentinelEntry; switch (reason) { case CacheItemRemovedReason.Expired: updateReason = CacheItemUpdateReason.Expired; break; case CacheItemRemovedReason.DependencyChanged: updateReason = CacheItemUpdateReason.DependencyChanged; if (entry.ExpensiveObjectDependency.HasChanged) { // If the expensiveObject has been removed explicitly by Cache.Remove, // return from the SentinelEntry removed callback // thus effectively removing the SentinelEntry from the cache. return; } break; case CacheItemRemovedReason.Underused: Debug.Fail("Reason should never be CacheItemRemovedReason.Underused since the entry was inserted as NotRemovable."); return; default: // do nothing if reason is Removed return; } CacheDependency cacheDependency; DateTime absoluteExpiration; TimeSpan slidingExpiration; object expensiveObject; CacheItemUpdateCallback callback = entry.CacheItemUpdateCallback; // invoke update callback try { callback(entry.Key, updateReason, out expensiveObject, out cacheDependency, out absoluteExpiration, out slidingExpiration); // Dev10 861163 - Only update the "expensive" object if the user returns a new object and the // cache dependency hasn't changed. (Inserting with a cache dependency that has already changed will cause recursion.) if (expensiveObject != null && (cacheDependency == null || !cacheDependency.HasChanged)) { HttpRuntime.Cache.Insert(entry.Key, expensiveObject, cacheDependency, absoluteExpiration, slidingExpiration, entry.CacheItemUpdateCallback); } else { HttpRuntime.Cache.Remove(entry.Key); } } catch (Exception e) { HttpRuntime.Cache.Remove(entry.Key); try { WebBaseEvent.RaiseRuntimeError(e, value); } catch { } } }
public static WebEvent FromWebBaseEvent(WebBaseEvent webBaseEvent) { var webEvent = new WebEvent { ApplicationPath = HostingEnvironment.ApplicationPhysicalPath, ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath, Details = webBaseEvent.ToString(), EventCode = webBaseEvent.EventCode, EventDetailCode = webBaseEvent.EventDetailCode, EventID = webBaseEvent.EventID, EventOccurrence = webBaseEvent.EventOccurrence, EventSequence = webBaseEvent.EventSequence, EventTime = webBaseEvent.EventTime, EventTimeUtc = webBaseEvent.EventTimeUtc, EventType = webBaseEvent.GetType().Name, Message = webBaseEvent.Message }; var baseErrorEvent = webBaseEvent as WebBaseErrorEvent; if (baseErrorEvent != null) { webEvent.ExceptionType = baseErrorEvent.ErrorException.GetType().Name; } return(webEvent); }
public override void ProcessEvent(WebBaseEvent eventRaised) { if (eventRaised != null) { if (UseBuffering) { base.ProcessEvent(eventRaised); } else { if (((System.Web.Management.WebBaseErrorEvent)eventRaised).ErrorException != null) { if (Convert.ToBoolean(WebConfigurationManager.AppSettings["WriteErrorToDb"])) { InsertEvent(eventRaised); SaveEvents(); } } else { InsertEvent(eventRaised); SaveEvents(); } } } }
public override void Raise() { customRaisedMsg = string.Format("Event raised at: {0}", DateTime.Now.TimeOfDay.ToString()); WebBaseEvent.Raise(this); }
public static void OnCacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason) { CacheItemUpdateReason expired; System.Web.Caching.CacheItemUpdateCallback callback; Cache.SentinelEntry entry = value as Cache.SentinelEntry; switch (reason) { case CacheItemRemovedReason.Expired: expired = CacheItemUpdateReason.Expired; goto Label_0034; case CacheItemRemovedReason.Underused: break; case CacheItemRemovedReason.DependencyChanged: expired = CacheItemUpdateReason.DependencyChanged; if (!entry.ExpensiveObjectDependency.HasChanged) { goto Label_0034; } break; default: return; } return; Label_0034: callback = entry.CacheItemUpdateCallback; try { CacheDependency dependency; DateTime time; TimeSpan span; object obj2; callback(entry.Key, expired, out obj2, out dependency, out time, out span); if ((obj2 != null) && ((dependency == null) || !dependency.HasChanged)) { HttpRuntime.Cache.Insert(entry.Key, obj2, dependency, time, span, entry.CacheItemUpdateCallback); } else { HttpRuntime.Cache.Remove(entry.Key); } } catch (Exception exception) { HttpRuntime.Cache.Remove(entry.Key); try { WebBaseEvent.RaiseRuntimeError(exception, value); } catch { } } }
// // callbacks // private static void HandleErrorWithoutContext(Exception e) { HttpApplicationFactory.RaiseError(e); try { WebBaseEvent.RaiseRuntimeError(e, typeof(OutputCache)); } catch { } }
internal static void ReportUrlAuthorizationFailure(HttpContext context, object webEventSource) { context.Response.StatusCode = 0x191; WriteErrorMessage(context); if ((context.User != null) && context.User.Identity.IsAuthenticated) { WebBaseEvent.RaiseSystemEvent(webEventSource, 0xfa7); } context.ApplicationInstance.CompleteRequest(); }
// </Snippet3> // <Snippet4> // Raises the SampleWebAuditEvent. public override void Raise() { // Perform custom processing. customRaisedMsg = string.Format("Event raised at: {0}", DateTime.Now.TimeOfDay.ToString()); // Raise the event. WebBaseEvent.Raise(this); }
private void Add(WebBaseEvent p_eventRaised) { Exception errorException = null; WebRequestInformation requestInformation = null; if (p_eventRaised is WebRequestEvent) { requestInformation = ((WebRequestEvent)p_eventRaised).RequestInformation; } else if (p_eventRaised is WebRequestErrorEvent) { requestInformation = ((WebRequestErrorEvent)p_eventRaised).RequestInformation; } else if (p_eventRaised is WebErrorEvent) { requestInformation = ((WebErrorEvent)p_eventRaised).RequestInformation; } else if (p_eventRaised is WebAuditEvent) { requestInformation = ((WebAuditEvent)p_eventRaised).RequestInformation; } if (p_eventRaised is WebBaseErrorEvent) { errorException = ((WebBaseErrorEvent)p_eventRaised).ErrorException; } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_Health("); strSql.Append("EventCode,Message,EventTime,RequestUrl,ExceptionType,ExceptionMessage)"); strSql.Append(" values ("); strSql.Append("@EventCode,@Message,@EventTime,@RequestUrl,@ExceptionType,@ExceptionMessage)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@EventCode", SqlDbType.Int, 4), new SqlParameter("@Message", SqlDbType.NVarChar, 50), new SqlParameter("@EventTime", SqlDbType.DateTime), new SqlParameter("@RequestUrl", SqlDbType.NVarChar, 255), new SqlParameter("@ExceptionType", SqlDbType.NVarChar, 255), new SqlParameter("@ExceptionMessage", SqlDbType.NVarChar, 255) }; parameters[0].Value = p_eventRaised.EventCode; parameters[1].Value = p_eventRaised.Message; parameters[2].Value = p_eventRaised.EventTime; parameters[3].Value = (requestInformation != null) ? requestInformation.RequestUrl : Convert.DBNull; parameters[4].Value = (errorException != null) ? errorException.GetType().ToString() : Convert.DBNull; parameters[5].Value = (errorException != null) ? errorException.Message : Convert.DBNull; object obj = SqlHelper.GetSingle(strSql.ToString(), parameters); }
private void AddBasicDataFields(LogRecord logrec, WebBaseEvent raisedEvent) { var applicationInformation = WebBaseEvent.ApplicationInformation; logrec.Server = applicationInformation.ApplicationPath; logrec.Server = applicationInformation.MachineName; logrec.TimeUtc = raisedEvent.EventTimeUtc; logrec.Message = raisedEvent.Message; logrec.LogLevel = LogRecord.ELogLevel.Info; logrec.LoggerName = String.Format("ASP.NET Health: {0}.{1}", raisedEvent.EventCode, raisedEvent.EventDetailCode); }
/// <summary>Processes the event passed to the provider.</summary> /// <param name="raisedEvent">The <see cref="WebBaseEvent"/> object to process.</param> public override void ProcessEvent(WebBaseEvent raisedEvent) { if (raisedEvent == null) { return; } LogEntry logEntry = CreateLogEntry(raisedEvent); this.loggingProvider.Log(logEntry); }
private static Exception GetExceptionFromWebEvent(WebBaseEvent eventRaised) { WebBaseErrorEvent errorEvent = eventRaised as WebBaseErrorEvent; if (errorEvent != null) { return(errorEvent.ErrorException); } return(null); }
internal void RaiseOnPipelineCompleted() { // The callbacks really shouldn't throw exceptions, but we have a catch block just in case. // Since there's nobody else that can listen for these errors (the request is unwinding and // user code will no longer run), we'll just log the error. try { _pipelineCompletedQueue.FireAndComplete(disposable => disposable.Dispose()); } catch (Exception e) { WebBaseEvent.RaiseRuntimeError(e, null); } }
/// <summary> /// Processes the incoming events. /// This method performs custom processing and, if buffering is enabled, /// it calls the base.ProcessEvent to buffer the event information. /// </summary> /// <param name="raisedEvent">The raised Event details</param> public override void ProcessEvent(WebBaseEvent raisedEvent) { if (UseBuffering) { base.ProcessEvent(raisedEvent); // Buffering enabled, call the base event to buffer event information. } else { // Store the information in the specified file. StoreToDB(raisedEvent); } }
internal override void RaiseTraceEvent(WebBaseEvent webEvent) { if ((IntPtr.Zero != base._ecb) && EtwTrace.IsTraceEnabled(webEvent.InferEtwTraceVerbosity(), 1)) { int num; string[] strArray; int[] numArray; string[] strArray2; int num2; webEvent.DeconstructWebEvent(out num2, out num, out strArray, out numArray, out strArray2); UnsafeNativeMethods.EcbEmitWebEventTrace(base._ecb, num2, num, strArray, numArray, strArray2); } }
private static LogEntry CreateLogEntry(WebBaseEvent eventRaised) { LoggingEventType eventType = GetEventTypeFromWebEvent(eventRaised); string message = string.Format(CultureInfo.InvariantCulture, "{0} (Event Code: {1})", eventRaised.Message, eventRaised.EventCode); string source = eventRaised.GetType().Name; Exception exception = GetExceptionFromWebEvent(eventRaised); return(new LogEntry(eventType, message, source, exception)); }
internal static void ReportUrlAuthorizationFailure(HttpContext context, object webEventSource) { // Deny access context.Response.StatusCode = 401; WriteErrorMessage(context); if (context.User != null && context.User.Identity.IsAuthenticated) { // We don't raise failure audit event for anonymous user WebBaseEvent.RaiseSystemEvent(webEventSource, WebEventCodes.AuditUrlAuthorizationFailure); } context.ApplicationInstance.CompleteRequest(); }
public override void ProcessEvent(WebBaseEvent raisedEvent) { var logrec = new LogRecord { AdditionalFields = new Dictionary <String, Object>() }; this.AddBasicDataFields(logrec, raisedEvent); if (raisedEvent is WebManagementEvent) { this.AddWebProcessInformationDataFields(logrec, ((WebManagementEvent)raisedEvent).ProcessInformation); } if (raisedEvent is WebRequestEvent) { this.AddWebRequestInformationDataFields(logrec, ((WebRequestEvent)raisedEvent).RequestInformation); } if (raisedEvent is WebBaseErrorEvent) { this.AddExceptionDataFields(logrec, ((WebBaseErrorEvent)raisedEvent).ErrorException); } if (raisedEvent is WebAuditEvent) { this.AddWebRequestInformationDataFields(logrec, ((WebAuditEvent)raisedEvent).RequestInformation); } if (raisedEvent is WebRequestErrorEvent) { logrec.LogLevel = LogRecord.ELogLevel.Error; this.AddWebRequestInformationDataFields(logrec, ((WebRequestErrorEvent)raisedEvent).RequestInformation); this.AddWebThreadInformationDataFields(logrec, ((WebRequestErrorEvent)raisedEvent).ThreadInformation); } if (raisedEvent is WebErrorEvent) { logrec.LogLevel = LogRecord.ELogLevel.Error; this.AddWebRequestInformationDataFields(logrec, ((WebErrorEvent)raisedEvent).RequestInformation); this.AddWebThreadInformationDataFields(logrec, ((WebErrorEvent)raisedEvent).ThreadInformation); } if (raisedEvent is WebAuthenticationSuccessAuditEvent) { logrec.AdditionalFields.Add("UserToSignIn", ((WebAuthenticationSuccessAuditEvent)raisedEvent).NameToAuthenticate); } if (raisedEvent is WebAuthenticationFailureAuditEvent) { logrec.AdditionalFields.Add("UserToSignIn", ((WebAuthenticationFailureAuditEvent)raisedEvent).NameToAuthenticate); } if (raisedEvent is WebViewStateFailureAuditEvent) { logrec.LogLevel = LogRecord.ELogLevel.Error; this.AddExceptionDataFields(logrec, ((WebViewStateFailureAuditEvent)raisedEvent).ViewStateException); } connector.SendLogRecord(logrec); }
public static bool Authenticate(string name, string password) { bool flag = InternalAuthenticate(name, password); if (flag) { PerfCounters.IncrementCounter(AppPerfCounter.FORMS_AUTH_SUCCESS); WebBaseEvent.RaiseSystemEvent(null, 0xfa1, name); return(flag); } PerfCounters.IncrementCounter(AppPerfCounter.FORMS_AUTH_FAIL); WebBaseEvent.RaiseSystemEvent(null, 0xfa5, name); return(flag); }
/// <summary> /// Processes the event passed to the provider. /// </summary> /// <param name="raisedEvent">The System.Web.Management.WebBaseEvent object to process.</param> public override void ProcessEvent(WebBaseEvent raisedEvent) { if (UseBuffering) { // If buffering is enabled, call the base class's // ProcessEvent method to buffer the event base.ProcessEvent(raisedEvent); } else { // If buffering is not enabled, log the Web event now LogEntry(FormatEntry(raisedEvent)); } }
public int ProcessRequest(IntPtr ecb, int iWRType) { IntPtr zero = IntPtr.Zero; if (iWRType == 2) { zero = ecb; ecb = System.Web.UnsafeNativeMethods.GetEcb(zero); } ISAPIWorkerRequest wr = null; try { bool useOOP = iWRType == 1; wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, useOOP); wr.Initialize(); string appPathTranslated = wr.GetAppPathTranslated(); string appDomainAppPathInternal = HttpRuntime.AppDomainAppPathInternal; if ((appDomainAppPathInternal == null) || StringUtil.EqualsIgnoreCase(appPathTranslated, appDomainAppPathInternal)) { HttpRuntime.ProcessRequestNoDemand(wr); return(0); } HttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.PhysicalApplicationPathChanged, System.Web.SR.GetString("Hosting_Phys_Path_Changed", new object[] { appDomainAppPathInternal, appPathTranslated })); return(1); } catch (Exception exception) { try { WebBaseEvent.RaiseRuntimeError(exception, this); } catch { } if ((wr == null) || !(wr.Ecb == IntPtr.Zero)) { throw; } if (zero != IntPtr.Zero) { System.Web.UnsafeNativeMethods.SetDoneWithSessionCalled(zero); } if (exception is ThreadAbortException) { Thread.ResetAbort(); } return(0); } }
// </Snippet4> // <Snippet5> // Process the event that has been raised. public override void ProcessEvent(WebBaseEvent raisedEvent) { if (msgCounter < maxMsgNumber) { // Buffer the event information. msgBuffer.Enqueue(raisedEvent); // Increment the message counter. msgCounter += 1; } else { // Flush the buffer. Flush(); } }
// Helper methods private string FormatEntry(WebBaseEvent e) { return String.Format("{0}\t{1}\t{2} (Event Code: {3})", e.EventTime, e.GetType().ToString(), e.Message, e.EventCode); }
public static void Raise(WebBaseEvent eventRaised) { }
public virtual void ProcessEvent(WebBaseEvent eventRaised) { }
public override void ProcessEvent(WebBaseEvent raisedEvent) { // Write an entry to the log file LogEntry(FormatEntry(raisedEvent)); }
// Methods public abstract virtual void ProcessEvent(WebBaseEvent raisedEvent) { }
public bool Contains(WebBaseEvent value) { }
// Methods public int IndexOf(WebBaseEvent value) { }