예제 #1
0
        public void PreContribute(AuditContributionContext context)
        {
            var httpContext = context.ServiceProvider.GetRequiredService <IHttpContextAccessor>().HttpContext;

            if (httpContext == null)
            {
                return;
            }
            var wapper = context.CreateWapper <AspNetCoreAuditInfoWapper>();

            wapper.CurrentUser = httpContext.User?.Identity?.Name ?? "Anonymous";
            if (wapper.HttpMethod == null)
            {
                wapper.HttpMethod = httpContext.Request.Method;
            }

            if (wapper.Url == null)
            {
                wapper.Url = BuildUrl(httpContext);
            }

            if (wapper.ClientIpAddress == null)
            {
                wapper.ClientIpAddress = GetClientIpAddress(httpContext);
            }

            if (wapper.BrowserInfo == null)
            {
                wapper.BrowserInfo = GetBrowserInfo(httpContext);
            }
        }
예제 #2
0
        public void PostContribute(AuditContributionContext context)
        {
            var httpContext = context.ServiceProvider.GetRequiredService <IHttpContextAccessor>().HttpContext;

            if (httpContext == null)
            {
                return;
            }
            var wapper = context.CreateWapper <AspNetCoreAuditInfoWapper>();

            if (wapper.HttpStatusCode == default)
            {
                wapper.HttpStatusCode = httpContext.Response.StatusCode;
            }
        }