public override void OnActionExecuting(ActionExecutingContext context) { base.OnActionExecuting(context); if (context.HttpContext.Request.Query.ContainsKey(dataqueryname)) { data = context.HttpContext.Request.Query[dataqueryname].ToString(); } if (context.HttpContext.Request.Query.ContainsKey(tokenqueryname)) { token = context.HttpContext.Request.Query[tokenqueryname].ToString(); } if (context.HttpContext.Request.Query.ContainsKey(useridqueryname)) { var struserid = context.HttpContext.Request.Query[useridqueryname].ToString(); long.TryParse(struserid, out userId); } var ip = HttpContext.Connection.RemoteIpAddress.ToString(); var tokenGrain = client.GetGrain <ITokenGrain>(userId); var tokenInfo = tokenGrain.GetToken().Result; if (tokenInfo.Token != token || tokenInfo.IP != ip || tokenInfo.LastTime.AddSeconds(GameConstants.TOKENEXPIRE) < DateTime.Now) { var result = new MOMsgResult(); result.ErrorCode = 10001; result.ErrorInfo = "Token Error"; context.HttpContext.Response.WriteAsync(JsonConvert.SerializeObject(result), Encoding.UTF8); return; } }
public void OnException(ExceptionContext context) { _logger.LogError(new EventId(context.Exception.HResult), context.Exception, context.Exception.Message); var result = new MOMsgResult() { ErrorCode = (int)MOErrorType.Hidden, ErrorInfo = "未知错误" }; context.HttpContext.Response.WriteAsync(JsonConvert.SerializeObject(result)); }