Esempio n. 1
0
        /// <summary>
        /// Sets the current Http context properties into corresponding properties of notice.
        /// </summary>
        public static void SetHttpContext(this Notice notice, IHttpContext httpContext, AirbrakeConfig config)
        {
            if (notice == null || httpContext == null)
            {
                return;
            }

            notice.HttpContext = httpContext;

            notice.Context.Url       = httpContext.Url;
            notice.Context.UserAddr  = httpContext.UserAddr;
            notice.Context.UserAgent = httpContext.UserAgent;

            if (httpContext.Action != null && httpContext.Component != null)
            {
                notice.Context.Action    = httpContext.Action;
                notice.Context.Component = httpContext.Component;
            }

            notice.Context.User = new UserInfo
            {
                Name  = httpContext.UserName,
                Id    = httpContext.UserId,
                Email = httpContext.UserEmail
            };

            if (config == null)
            {
                notice.Params          = httpContext.Parameters;
                notice.EnvironmentVars = httpContext.EnvironmentVars;
                notice.Session         = httpContext.Session;
            }
            else
            {
                var blackListRegex = Utils.CompileRegex(config.Blocklist);
                var whiteListRegex = Utils.CompileRegex(config.Allowlist);

                notice.Params          = Utils.FilterParameters(httpContext.Parameters, blackListRegex, whiteListRegex);
                notice.EnvironmentVars = Utils.FilterParameters(httpContext.EnvironmentVars, blackListRegex, whiteListRegex);
                notice.Session         = Utils.FilterParameters(httpContext.Session, blackListRegex, whiteListRegex);
            }
        }