Esempio n. 1
0
        public async Task <ResponseBase> Logout()
        {
            var resp      = new ResponseBase();
            var loginName = HttpContext?.User?.FindFirst(p => p.Type == Constants.LOGINNAME)?.Value;

            if (string.IsNullOrEmpty(loginName))
            {
                return(resp.Fail("未获取到登录信息"));
            }
            await _redisClient.GetDatabase().KeyDeleteAsync(loginName);

            return(resp);
        }
        public async Task InvokeAsync(HttpContext context)
        {
            try
            {
                await _next.Invoke(context);
            }
            catch (Exception e)
            {
                context.Response.StatusCode = 200;

                context.Response.ContentType = "application/json";

                string jsonString = JsonConvert.SerializeObject(ResponseBase.Fail(e.Message));

                await context.Response.WriteAsync(jsonString, Encoding.UTF8);

                return;
            }
        }