當前位置: 首頁>>代碼示例>>C#>>正文


C# Mvc.ActionExecutingContext類代碼示例

本文整理匯總了C#中System.Web.Mvc.ActionExecutingContext的典型用法代碼示例。如果您正苦於以下問題:C# ActionExecutingContext類的具體用法?C# ActionExecutingContext怎麽用?C# ActionExecutingContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ActionExecutingContext類屬於System.Web.Mvc命名空間,在下文中一共展示了ActionExecutingContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnActionExecuting

 /// <summary>
 /// 액션 메서드가 불려지기 전 호출되는 메서드
 /// </summary>
 /// <param name="filterContext">ControllerContext 하위 클래스</param>
 public void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (filterContext.HttpContext.Request.IsLocal)
     {
         filterContext.Result = new HttpNotFoundResult();
     }
 }
開發者ID:mz-jung,項目名稱:Filter,代碼行數:11,代碼來源:CustomActionAttribute.cs

示例2: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var message = string.Format("Start executing action {1} from {0}Controller", filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                                                                    filterContext.ActionDescriptor.ActionName);

            _logger.Trace(message);
        }
開發者ID:inatoff,項目名稱:ACTS_Site,代碼行數:7,代碼來源:LogFilterAttribute.cs

示例3: OnActionExecuting

 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (!(filterContext.HttpContext.Request.IsAjaxRequest()))
     {
         filterContext.Result = new HttpNotFoundResult();
     }
 }
開發者ID:DennyGD,項目名稱:PetFinder,代碼行數:7,代碼來源:AjaxOnlyAttribute.cs

示例4: OnActionExecuting

		public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null || filterContext.HttpContext == null)
                return;

            HttpRequestBase request = filterContext.HttpContext.Request;
            if (request == null)
                return;

            //don't apply filter to child methods
            if (filterContext.IsChildAction)
                return;

            if (request.QueryString != null && request.QueryString["AffiliateId"] != null)
            {
                var affiliateId = Convert.ToInt32(request.QueryString["AffiliateId"]);

                if (affiliateId > 0)
                {
                    var affiliateService = AffiliateService.Value;
                    var affiliate = affiliateService.GetAffiliateById(affiliateId);
                    if (affiliate != null && !affiliate.Deleted && affiliate.Active)
                    {
                        var workContext = WorkContext.Value;
                        if (workContext.CurrentCustomer != null &&
                            workContext.CurrentCustomer.AffiliateId != affiliate.Id)
                        {
                            workContext.CurrentCustomer.AffiliateId = affiliate.Id;
                            var customerService = CustomerService.Value;
                            customerService.UpdateCustomer(workContext.CurrentCustomer);
                        }
                    }
                }
            }
        }
開發者ID:boatengfrankenstein,項目名稱:SmartStoreNET,代碼行數:35,代碼來源:CheckAffiliateAttribute.cs

示例5: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (string.IsNullOrEmpty(_ignoreParameter) || string.IsNullOrEmpty(filterContext.RequestContext.HttpContext.Request.QueryString[_ignoreParameter]))
            {
                if (!BrowserUtility.BrowserUtility.SideInWeixinBrowser(filterContext.HttpContext))
                {
                    //TODO:判斷網頁版登陸狀態
                    ActionResult actionResult = null;
                    if (!string.IsNullOrEmpty(RedirectUrl))
                    {
                        actionResult = new RedirectResult(RedirectUrl);
                    }
                    else
                    {
                        actionResult = new ContentResult()
                        {
                            Content = _message
                        };
                    }

                    filterContext.Result = actionResult;
                }
            }

            base.OnActionExecuting(filterContext);
        }
開發者ID:JeffreySu,項目名稱:WeiXinMPSDK,代碼行數:26,代碼來源:WeixinInternalRequestAttribute.cs

示例6: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //Stores the Request in an Accessible object
            var request = filterContext.HttpContext.Request;

            //Generate the appropriate key based on the user's Authentication Cookie
            //This is overkill as you should be able to use the Authorization Key from
            //Forms Authentication to handle this. 
            //var sessionIdentifier = string.Join("", MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(request.Cookies[FormsAuthentication.FormsCookieName].Value)).Select(s => s.ToString("x2")));

            //Generate an audit
            Audit audit = new Audit()
            {
               // SessionID = sessionIdentifier,
                AuditID = Guid.NewGuid(),
                IPAddress = request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.UserHostAddress,
                URLAccessed = request.RawUrl,
                TimeAccessed = DateTime.Now,
                UserName = (request.IsAuthenticated) ? filterContext.HttpContext.User.Identity.Name : "Anonymous",
                TotalBytes = request.TotalBytes,
                Browser = request.Browser.Type,
                Data = SerializeRequest(request)
            };

            //Stores the Audit in the Database
            AuditingContext context = new AuditingContext();
            context.AuditRecords.Add(audit);
            context.SaveChanges();

            base.OnActionExecuting(filterContext);
        }
開發者ID:Aimtjie,項目名稱:LogistiX,代碼行數:31,代碼來源:AuditingModels.cs

示例7: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!this.Enable)
                return;

            var request = filterContext.RequestContext.HttpContext.Request;
            var acceptEncoding = request.Headers.Get("Accept-Encoding");

            if (string.IsNullOrEmpty(acceptEncoding))
                return;

            acceptEncoding = acceptEncoding.ToUpper();
            var response = filterContext.RequestContext.HttpContext.Response;

            if (acceptEncoding.Contains("GZIP"))
            {
                response.AppendHeader("Content-Encoding", "gzip");
                response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
            }
            else if (acceptEncoding.Contains("DEFLATE"))
            {
                response.AppendHeader("Content-Encoding", "deflate");
                response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
            }
        }
開發者ID:wilsonwu,項目名稱:APILiteNET,代碼行數:25,代碼來源:CompressAttribute.cs

示例8: AuthorizeCore

        //權限判斷業務邏輯
        protected virtual bool AuthorizeCore(ActionExecutingContext filterContext, bool isViewPage)
        {
            if (filterContext.HttpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                return false;//判定用戶是否登錄
            }
            //var user = new CurrentUser();//獲取當前用戶信息
            //var controllerName = filterContext.RouteData.Values["controller"].ToString();
            //var actionName = filterContext.RouteData.Values["action"].ToString();
            //if (isViewPage && (controllerName.ToLower() != "main" && actionName.ToLower() != "masterpage"))//如果當前Action請求為具體的功能頁並且不是MasterPage頁
            //{
            //    if (user.MenuPermission.Count(m => m.ControllerName == controllerName && m.ActionName == actionName) == 0)
            //        return false;
            //}
            //else
            //{
            //    var actions = ContainerFactory.GetContainer().Resolve<IAuthorityFacade>().GetAllActionPermission();//所有被維護的Action權限
            //    if (actions.Count(a => a.ControllerName == controllerName && a.ActionName == actionName) != 0)//如果當前Action屬於被維護的Action權限
            //    {
            //        if (user.ActionPermission.Count(a => a.ControllerName == controllerName && a.ActionName == actionName) == 0)
            //            return false;
            //    }
            //}
            return true;
        }
開發者ID:wangjingli,項目名稱:General.test,代碼行數:31,代碼來源:AuthorizeFilterAttribute.cs

示例9: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            /* 注釋
            ----------------------------------------------------------*/

            /*
               var values = filterContext.RouteData.Values;
               if ((values["Controller"].ToString().ToLower() == "sysloginmanage")
               )
               return;

               filterContext.HttpContext.Response.Write("<script type='text/javascript'>window.location.href='www.bing.com'</script>&nbsp;");
               filterContext.HttpContext.Response.End();

               if (SysContext.CurrentSysUser == null)
               {
               if (values["Controller"].ToString().ToLower() == "exporthelper")
                   filterContext.HttpContext.Response.Write("<script type='text/javascript'>window.returnValue='401 ';window.close();</script>&nbsp;");
               else if(values["Controller"].ToString().ToLower() == "home")
                   filterContext.HttpContext.Response.Write("<script type='text/javascript'>window.location.href='/sysloginmanage/index'</script>&nbsp;");
               else
                   filterContext.HttpContext.Response.Write("<script type='text/javascript'>window.top.redirectToLogin();</script>&nbsp;");
               filterContext.HttpContext.Response.End();
               }*/
        }
開發者ID:dalinhuang,項目名稱:cndreams,代碼行數:25,代碼來源:AdminFilter.cs

示例10: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // Redirect if not authenticated
            var controller = filterContext.RouteData.Values["controller"].ToString();

            if (!filterContext.IsChildAction && !filterContext.HttpContext.User.Identity.IsAuthenticated && controller != "Auth" && controller != "Error")
            {
                // Use the current url for the redirect
                string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath;

                // Send them off to the login page
                var loginUrl = _useReturnUrl
                    ? string.Format("~/Auth/LogOn?ReturnUrl={0}", redirectOnSuccess)
                    : "~/Auth/LogOn";

                if (_useRewrite)
                {
                    filterContext.Result = new RewriteResult(loginUrl);
                }
                else
                {
                    filterContext.Result = new RedirectResult(loginUrl);
                }
            }
        }
開發者ID:SharePointSusan,項目名稱:Research-Data-Manager,代碼行數:25,代碼來源:AuthenticationAttributes.cs

示例11: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            var area = filterContext.RouteData.DataTokens["area"];

            var controllerName = filterContext.RouteData.Values["controller"].ToString();
            var actionName = filterContext.RouteData.Values["action"].ToString();


            var path = filterContext.HttpContext.Request.Path.ToLower();
            if (path == "/" || path == "/Main/Login".ToLower() || path == "/Main/UserLogin".ToLower())
                return;//忽略對Login登錄頁的權限判定

            object[] attrs = filterContext.ActionDescriptor.GetCustomAttributes(typeof(ViewPageAttribute), true);
            var isViewPage = attrs.Length == 1;//當前Action請求是否為具體的功能頁

            if (this.AuthorizeCore(filterContext, isViewPage) == false)//根據驗證判斷進行處理
            {
                //注:如果未登錄直接在URL輸入功能權限地址提示不是很友好;如果登錄後輸入未維護的功能權限地址,那麽也可以訪問,這個可能會有安全問題
                if (isViewPage == true)
                {
                    filterContext.Result = new HttpUnauthorizedResult();//直接URL輸入的頁麵地址跳轉到登陸頁
                }
                else
                {
                    filterContext.Result = new ContentResult { Content = @"JsHelper.ShowError('抱歉,你不具有當前操作的權限!')" };//功能權限彈出提示框
                }
            }
        }
開發者ID:wangjingli,項目名稱:General.test,代碼行數:33,代碼來源:AuthorizeFilterAttribute.cs

示例12: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext c)
        {
            var key = string.Concat(Name, "-", c.HttpContext.Request.UserHostAddress);
            var allowExecute = false;

            if (HttpRuntime.Cache[key] == null)
            {
                HttpRuntime.Cache.Add(key,
                    true, // is this the smallest data we can have?
                    null, // no dependencies
                    DateTime.Now.AddSeconds(Seconds), // absolute expiration
                    Cache.NoSlidingExpiration,
                    CacheItemPriority.Low,
                    null); // no callback

                allowExecute = true;
            }

            if (!allowExecute)
            {
                if (String.IsNullOrEmpty(Message))
                    Message = "You may only perform this action every {n} seconds.";

                c.Result = new ContentResult { Content = Message.Replace("{n}", Seconds.ToString()) };
                // see 409 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
                c.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;
            }
        }
開發者ID:OpenDDD,項目名稱:dddmelbourne,代碼行數:28,代碼來源:ThrottleAttribute.cs

示例13: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpRequestBase request = filterContext.HttpContext.Request;

            string acceptEncoding = request.Headers["Accept-Encoding"];

            if (string.IsNullOrEmpty(acceptEncoding))
            {
                return;
            }
            else
            {
                acceptEncoding = acceptEncoding.ToUpperInvariant();

                HttpResponseBase response = filterContext.HttpContext.Response;

                if (acceptEncoding.Contains("GZIP"))
                {
                    response.AppendHeader("Content-encoding", "gzip");
                    response.Filter = CompressFilterActionAttribute.Gzip(response.Filter);
                }
                else if (acceptEncoding.Contains("DEFLATE"))
                {
                    response.AppendHeader("Content-encoding", "deflate");
                    response.Filter = CompressFilterActionAttribute.Deflate(response.Filter);
                }
            }
        }
開發者ID:jordivila,項目名稱:Net_MVC_NLayer_Generator,代碼行數:28,代碼來源:CompressFilter.cs

示例14: OnActionExecuting

 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     //在Action執行前執行
     //此處獲取用戶角色:成功則執行,失敗不執行
     ErrorRedirect(filterContext);
     base.OnActionExecuting(filterContext);
 }
開發者ID:Yumwey,項目名稱:BootStrapCss,代碼行數:7,代碼來源:PublishAttribute.cs

示例15: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // do base action first to ensure we have our context objects like mtapp
            base.OnActionExecuting(filterContext);

            // skip everything if we're a store controller with closed actions, etc.
            if (filterContext.Controller is Controllers.StoreController) return;

            // otherwise check for a store closed page
            if (filterContext.Controller is Controllers.Shared.BaseStoreController)
            {
                MerchantTribeApplication app = ((Controllers.Shared.BaseStoreController)filterContext.Controller).MTApp;
                if (app != null)
                {
                    if (app.CurrentRequestContext.CurrentStore.Settings.StoreClosed)
                    {
                        bool hasPass = false;
                        string guestPass = SessionManager.StoreClosedGuestPasswordForCurrentUser;
                        if (guestPass.Trim().Length > 0)
                        {
                            if (guestPass == app.CurrentStore.Settings.StoreClosedGuestPassword)
                            {
                                hasPass = true;
                            }
                        }
                        if (app.CurrentRequestContext.IsAdmin(app) == false && hasPass == false)
                        {
                            filterContext.Result = new RedirectResult("~/storeclosed");
                        }
                    }
                }
            }            
        }
開發者ID:appliedi,項目名稱:MerchantTribe,代碼行數:33,代碼來源:StoreClosedFilterAttribute.cs


注:本文中的System.Web.Mvc.ActionExecutingContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。