public override string GetVaryByCustomString(HttpContext context, string custom) { if (custom == "device") { string deviceType = string.Empty; if (HelperController.IsMobile()) { deviceType = "Mobile"; } else { deviceType = "PC"; } //return context.Request.Browser.Browser + // context.Request.Browser.MajorVersion; return(deviceType); } else { return(base.GetVaryByCustomString(context, custom)); } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { // Detecting Device ViewBag._IsMobile = HelperController.IsMobile(); #region Select View ( PC / Mobile ) string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); ViewBag._ViewName = actionName; // Web.config 에 IsMobileViewSupport 설정에 따라 string isMobileViewSupport = ConfigurationManager.AppSettings["IsMobileViewSupport"].ToString(); if (isMobileViewSupport.ToUpper().Equals("Y")) { // Mobile View 대상이 아닌 Action 검사 string[] ignoredActions = ConfigurationManager.AppSettings["IgnoredActions"].Split(new string[1] { "|" }, StringSplitOptions.RemoveEmptyEntries); bool isIgnoredAction = false; foreach (string n in ignoredActions) { if (actionName.ToLower().Equals(n.ToLower())) { isIgnoredAction = true; break; } } // Formal View 의 경우 모바일 / PC 분기 ( Custom Partial View 의 경우 따로 분기 처리 하지 않음 ) if (!string.IsNullOrEmpty(actionName) && actionName.Substring(0, 1) != "_" && isIgnoredAction == false) { string viewName = HelperController.GetViewName((Controller)this.ControllerContext.Controller, this.ControllerContext.RouteData.Values["action"].ToString()); // View 가 존재하지 않아 Response.Redirect 처리 됐을 경우 더 이상 서버 요소 변경하지 않아야 함. ( Warning 유발 방지 ) if (viewName.Equals("-1")) { filterContext.Result = new RedirectResult("/package/main"); return; } ViewBag._ViewName = viewName; } } else { // Action 에서의 Data 처리가 Mobile 로 분기되는 것을 막기 위해 False 처리 ViewBag._IsMobile = false; } #endregion / Select View ( PC / Mobile ) }