public Task InvokeAsync(HttpContext context) { //可选参数始终不为null string findPath = _filterApis.FirstOrDefault(x => x == context.Request.Path); if (!string.IsNullOrEmpty(findPath)) { return(_next(context)); } var token = context.Request.Headers["Token"]; if (string.IsNullOrEmpty(token)) { return(context.Response.WriteAsync(JsonConvert.SerializeObject( new MiddleResponse(ResponseStatus.TokenError, null)))); ; } var status = TokenTool.ParseToken(token, out var id); if (status != ResponseStatus.Success) { return(context.Response.WriteAsync(JsonConvert.SerializeObject( new MiddleResponse(status, null)))); } context.Request.Headers["id"] = id.ToString(); return(_next(context)); }
public KeyValuePair <bool, long> TokenValidation(string token) { var status = TokenTool.ParseToken(token, out var id); if (status != ResponseStatus.Success) { return(new KeyValuePair <bool, long>(false, id)); } return(new KeyValuePair <bool, long>(true, id)); }