コード例 #1
0
        public Task <FilterResult> FilterAsync(FilterAttribute attribute, MiddlewareData data)
        {
            var principal = data.Features.RequireOne <AuthenticationFeature>().Principal;

            if (!principal.Is​Authenticated())
            {
                var message = new BaseOutMessage()
                {
                    Text = "Unauthorized access"
                };
                var result = FilterResult.BreakExecution(data.AddRenderMessageFeature(message));
                return(Task.FromResult(result));
            }
            return(Task.FromResult(FilterResult.NextFilter(data)));
        }