• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Mvc.ActionExecutingContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.Mvc.ActionExecutingContext的典型用法代码示例。如果您正苦于以下问题:C# ActionExecutingContext类的具体用法?C# ActionExecutingContext怎么用?C# ActionExecutingContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ActionExecutingContext类属于System.Web.Mvc命名空间,在下文中一共展示了ActionExecutingContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: OnActionExecuting

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (filterContext.HttpContext.User.Identity is WindowsIdentity)
     {
         throw new InvalidOperationException("Windows authentication is not supported.");
     }
 }
开发者ID:DannyDouglass,项目名称:DCStreetHockey.Original,代码行数:7,代码来源:AccountController.cs


示例17: OnActionExecuting

        /// <summary>
        /// Happens before the action starts running
        /// </summary>
        /// <param name="filterContext">The filter Context.</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var mp = MiniProfiler.Current;
            if (mp != null)
            {
                var stack = HttpContext.Current.Items[StackKey] as Stack<IDisposable>;
                if (stack == null)
                {
                    stack = new Stack<IDisposable>();
                    HttpContext.Current.Items[StackKey] = stack;
                }

                var profiler = MiniProfiler.Current;
                if (profiler != null)
                {
                    var tokens = filterContext.RouteData.DataTokens;
                    string area = tokens.ContainsKey("area") && !string.IsNullOrEmpty((string)tokens["area"]) ?
                        tokens["area"] + "." : string.Empty;
                    string controller = filterContext.Controller.ToString().Split('.').Last() + ".";
                    string action = filterContext.ActionDescriptor.ActionName;

                    stack.Push(profiler.Step("Controller: " + area + controller + action));
                }

            }
            base.OnActionExecuting(filterContext);
        }
开发者ID:krk,项目名称:MiniProfiler,代码行数:31,代码来源:ProfilingActionFilter.cs


示例18: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var rd = filterContext.RequestContext.RouteData;
            string currentAction = rd.GetRequiredString("action");
            string currentController = rd.GetRequiredString("controller");
            string currentArea = rd.Values["area"] as string;

            if (currentController == "Home" && currentAction == "SinServicio")
            {
                base.OnActionExecuting(filterContext);
            }
            else
            {
                var estadoServicio = ConfiguracionService.GetConfiguracion("EstadoSitio");

                if (!Convert.ToBoolean(estadoServicio.Valor))
                {
                    filterContext.Result = new RedirectToRouteResult(
                        new RouteValueDictionary
                        {
                            {"Controller", "Home"},
                            {"Action", "SinServicio"}
                        });
                }
                else
                {
                    base.OnActionExecuting(filterContext);
                }
            }
        }
开发者ID:JotaEmePM,项目名称:FacilFactura,代码行数:30,代码来源:EstadoServicioAttribute.cs


示例19: OnActionExecuting

 public void OnActionExecuting(ActionExecutingContext filterContext)
 {
     var session = _sessionFactory.OpenSession();
     session.FlushMode = FlushMode.Auto;
     CurrentSessionContext.Bind(session);
     session.BeginTransaction();
 }
开发者ID:carlospeix,项目名称:ConfUi,代码行数:7,代码来源:SessionPerActionAttribute.cs


示例20: OnActionExecuting

 public override void OnActionExecuting(ActionExecutingContext filterContext) {
     if(!ApplicationIsConfigured() && !IsInSetupController(filterContext)) {
         filterContext.Result = new RedirectResult(new UrlHelper(filterContext.RequestContext).RouteUrl("setup"));
         return;
     }
     base.OnActionExecuting(filterContext);
 }
开发者ID:santosh-mnrec,项目名称:AzurePlot,代码行数:7,代码来源:NeedsSetupAttribute.cs



注:本文中的System.Web.Mvc.ActionExecutingContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.ActionResult类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.ActionExecutedContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap