public override void OnActionExecuted(ActionExecutedContext filterContext) { bool clientFlag = filterContext.HttpContext.Request.Headers.AllKeys.Contains("x-soho-app-id"); if (clientFlag) { string ServiceAppId = ConfigurationManager.AppSettings["AppId"]; ServiceAppId = string.IsNullOrWhiteSpace(ServiceAppId) ? "" : ServiceAppId; filterContext.HttpContext.Response.AddHeader("x-soho-app-id", ServiceAppId); bool bIsMustBusinessRoute = ValidateIsMustBusinessRoute(filterContext.RouteData.Values["controller"].ToString(), filterContext.RouteData.Values["action"].ToString()); if (bIsMustBusinessRoute) { //HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.OK; HttpContext.Current.Response.Write(SerializationUtility.JsonSerialize3(new PortalResult { Code = 1000001, Success = false, Message = "您没有操作权限!" })); HttpContext.Current.Response.End(); return; } else { //客户端存在自定义标识,则是非Web方式请求,直接返回Json数据 ViewResult viewResult = filterContext.Result as ViewResult; if (viewResult != null) { var modelData = viewResult.Model as PortalResult; //是否返回自定义cookie string serviceSohoOrigin = ConfigurationManager.AppSettings["SohoOrigin"]; serviceSohoOrigin = string.IsNullOrWhiteSpace(serviceSohoOrigin) ? "" : serviceSohoOrigin; if (filterContext.HttpContext.Request.Headers.AllKeys.Contains("x-soho-origin") && serviceSohoOrigin.Contains(filterContext.HttpContext.Request.Headers["x-soho-origin"].ToString())) { MobilePortalResult responseData = new MobilePortalResult(modelData); var mobileCookie = HttpContext.Current.Response.Headers["x-soho-mobile-cookie"] == null ? "" : HttpContext.Current.Response.Headers["x-soho-mobile-cookie"].ToString(); responseData.Cookie = mobileCookie; HttpContext.Current.Response.Write(SerializationUtility.JsonSerialize3(responseData)); HttpContext.Current.Response.End(); } else { HttpContext.Current.Response.Write(SerializationUtility.JsonSerialize3(modelData)); HttpContext.Current.Response.End(); } throw new BusinessException(""); } } } }
public override void OnActionExecuted(ActionExecutedContext filterContext) { bool clientFlag = filterContext.HttpContext.Request.Headers.AllKeys.Contains("x-soho-app-id"); if (clientFlag) { string ServiceAppId = ConfigurationManager.AppSettings["AppId"]; ServiceAppId = string.IsNullOrWhiteSpace(ServiceAppId) ? "" : ServiceAppId; filterContext.HttpContext.Response.AddHeader("x-soho-app-id", ServiceAppId); bool bIsMustBusinessRoute = ValidateIsMustBusinessRoute(filterContext.RouteData.Values["controller"].ToString(), filterContext.RouteData.Values["action"].ToString()); if (bIsMustBusinessRoute) { //HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.OK; HttpContext.Current.Response.Write(SerializationUtility.JsonSerialize3(new PortalResult { Code = 1000001, Success = false, Message = "您没有操作权限!" })); HttpContext.Current.Response.End(); return; } else { //客户端存在自定义标识,则是非Web方式请求,直接返回Json数据 ViewResult viewResult = filterContext.Result as ViewResult; if (viewResult != null) { var modelData = viewResult.Model as PortalResult; //是否返回自定义cookie string serviceSohoOrigin = ConfigurationManager.AppSettings["SohoOrigin"]; serviceSohoOrigin = string.IsNullOrWhiteSpace(serviceSohoOrigin) ? "" : serviceSohoOrigin; if (filterContext.HttpContext.Request.Headers.AllKeys.Contains("x-soho-origin") && serviceSohoOrigin.Contains(filterContext.HttpContext.Request.Headers["x-soho-origin"].ToString())) { MobilePortalResult responseData = new MobilePortalResult(modelData); var mobileCookie = HttpContext.Current.Response.Headers["x-soho-mobile-cookie"] == null ? "" : HttpContext.Current.Response.Headers["x-soho-mobile-cookie"].ToString(); responseData.Cookie = mobileCookie; HttpContext.Current.Response.Write(SerializationUtility.JsonSerialize3(responseData)); HttpContext.Current.Response.End(); } else { HttpContext.Current.Response.Write(SerializationUtility.JsonSerialize3(modelData)); HttpContext.Current.Response.End(); } throw new BusinessException(""); } } } }