public override void OnActionExecuting(HttpActionContext actionContext) { IEnumerable <string> sessions; string[] pathStrings = actionContext.Request.RequestUri.AbsolutePath.Split('/'); string method = pathStrings[pathStrings.Length - 1]; if (!"getSession".Equals(method)) { if (actionContext.Request.Headers.TryGetValues("em_session", out sessions)) { string session = sessions.FirstOrDefault(); if (string.IsNullOrWhiteSpace(session) || !session.Equals(SimpleCacheHelper <string> .GetCache("session"))) { BasicModelResponse <string> response = new BasicModelResponse <string>() { ErrCode = -1, Status = -2, Data = new List <string>() { "session过期" } }; HttpResponseMessage responseMessage = new HttpResponseMessage(); responseMessage.Content = new StringContent(JsonConvert.SerializeObject(response)); responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); actionContext.Response = responseMessage; return; } base.OnActionExecuting(actionContext); } else { BasicModelResponse <string> response = new BasicModelResponse <string>() { ErrCode = -1, Status = -2, Data = new List <string>() { "session过期" } }; HttpResponseMessage responseMessage = new HttpResponseMessage(); responseMessage.Content = new StringContent(JsonConvert.SerializeObject(response)); responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); actionContext.Response = responseMessage; } } base.OnActionExecuting(actionContext); }
public BasicModelResponse <int> testMethod() { List <int> resList = new List <int>(); try { int x = int.Parse("100"); resList.Add(x); return(BasicModelResponse <int> .GetSuccessEntity(resList)); } catch (Exception e) { // LogHelper.Current.WriteErrorLog(model.inputStr, e); return(BasicModelResponse <int> .GetFailedEntity(resList, "执行失败", -1, -1)); } }