Ejemplo n.º 1
0
        // Token: 0x06000012 RID: 18 RVA: 0x0000278C File Offset: 0x0000098C
        private static void ApplicationEndRequest(object sender, EventArgs e)
        {
            if (!FailFastUserCache.FailFastEnabled)
            {
                return;
            }
            Logger.EnterFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationEndRequest");
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     context         = httpApplication.Context;

            if (context == null || context.Request == null || context.Response == null)
            {
                Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "context == null || context.Request == null || context.Response == null", new object[0]);
                Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationEndRequest");
                return;
            }
            if (!context.Request.IsAuthenticated)
            {
                Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Return directly for un-authenticated request.", new object[0]);
                Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationEndRequest");
                return;
            }
            string text = context.Response.Headers[FailFastModule.headerKeyToStoreUserToken];

            Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Current UserToken is {0}.", new object[]
            {
                text
            });
            if (!string.IsNullOrEmpty(text))
            {
                int statusCode = context.Response.StatusCode;
                Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Response status code: {0}.", new object[]
                {
                    statusCode
                });
                if (statusCode == 200)
                {
                    ConnectedUserManager.AddUser(text);
                }
                else if (statusCode == 500)
                {
                    ConnectedUserManager.RefreshUser(text);
                }
            }
            Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationEndRequest");
        }
Ejemplo n.º 2
0
		private static void ApplicationBeginRequest(object sender, EventArgs e)
		{
			if (!FailFastUserCache.FailFastEnabled)
			{
				return;
			}
			Logger.EnterFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
			HttpApplication httpApplication = (HttpApplication)sender;
			HttpContext context = httpApplication.Context;
			string text = null;
			foreach (IUserTokenParser userTokenParser in FailFastModule.tokenParsers)
			{
				if (userTokenParser.TryParseUserToken(context, out text))
				{
					Logger.TraceInformation(ExTraceGlobals.FailFastModuleTracer, "{0} module parses the user token successfully. User token parsed: {1}.", new object[]
					{
						userTokenParser.GetType(),
						text
					});
					break;
				}
			}
			if (string.IsNullOrEmpty(text))
			{
				Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "No usertoken is parsed, exit directly.", new object[0]);
				Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
				return;
			}
			if (context == null || context.Response == null)
			{
				Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "context == null || context.Response == null", new object[0]);
				Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
				return;
			}
			context.Response.Headers[FailFastModule.headerKeyToStoreUserToken] = text;
			string userTenant = FailFastModule.GetUserTenant(context, text);
			Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Tenant for current user {0} is {1} (If not email domain, it is in Delegated scenario).", new object[]
			{
				text,
				userTenant
			});
			string text2;
			FailFastUserCacheValue failFastUserCacheValue;
			BlockedReason blockedReason;
			if (!FailFastUserCache.Instance.IsUserInCache(text, userTenant, out text2, out failFastUserCacheValue, out blockedReason))
			{
				Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Http request of User {0} is not handled by FailFastModule because it is not in FailFastUserCache.", new object[]
				{
					text
				});
				Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
				return;
			}
			if (!ConnectedUserManager.ShouldFailFastUserInCache(text, text2, failFastUserCacheValue, blockedReason))
			{
				Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Http request of User {0} is not considered to be FailFast case. CacheKey: {1}. CacheValue: {2}. BlockedReason {3}.", new object[]
				{
					text,
					text2,
					failFastUserCacheValue,
					blockedReason
				});
				Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
				return;
			}
			Logger.LogEvent(TaskEventLogConstants.Tuple_LogUserRequestIsFailed, text2, new object[]
			{
				text,
				text2,
				failFastUserCacheValue.ToString()
			});
			Logger.TraceError(ExTraceGlobals.FailFastModuleTracer, "Http request of User {0} is terminated in fail-fast module.", new object[]
			{
				text
			});
			FailFastModule.perfCounter.RequestsBeFailFasted.RawValue = FailFastModule.perfCounter.RequestsBeFailFasted.RawValue + 1L;
			HttpLogger.SafeSetLogger(RpsHttpMetadata.FailFast, string.Concat(new object[]
			{
				text,
				"+",
				blockedReason,
				"+",
				(failFastUserCacheValue == null) ? "Null" : failFastUserCacheValue.HitCount.ToString()
			}));
			ConnectedUserManager.RemoveUser(text);
			string responseErrorMessage = FailFastModule.GetResponseErrorMessage(blockedReason);
			context.Response.ContentType = "application/soap+xml;charset=UTF-8";
			context.Response.Write(responseErrorMessage);
			context.Response.StatusCode = 400;
			context.Response.SubStatusCode = 350;
			context.Response.TrySkipIisCustomErrors = true;
			WinRMInfo.SetFailureCategoryInfo(context.Response.Headers, FailureCategory.FailFast, blockedReason.ToString());
			Logger.TraceInformation(ExTraceGlobals.FailFastModuleTracer, "Sending 400.350 to the client.", new object[0]);
			context.Response.End();
			Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
		}