当前位置: 首页>>代码示例>>C#>>正文


C# ActionDescriptor.GetCustomAttributes方法代码示例

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


在下文中一共展示了ActionDescriptor.GetCustomAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecutedAttributesOf

        private static IEnumerable<FilterAttribute> ExecutedAttributesOf(ActionDescriptor actionDescriptor)
        {
            var actionCustomAttributes = actionDescriptor.GetCustomAttributes(inherit: true).OfType<FilterAttribute>().OrderByDescending(attribute => attribute.Order);
            var controllerCustomAttributes = actionDescriptor.ControllerDescriptor.GetCustomAttributes(inherit: true).OfType<FilterAttribute>().OrderByDescending(attribute => attribute.Order);

            return actionCustomAttributes.Concat(controllerCustomAttributes);
        }
开发者ID:TrangHoang,项目名称:Scratchpad,代码行数:7,代码来源:ActionFilterDispatcher.cs

示例2: GetFilters

        public IEnumerable<System.Web.Mvc.Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            //if ((controllerContext.Controller is ProductController || controllerContext.Controller is ProductsController) &&
            //    actionDescriptor.ActionName.Equals("ProductList", 
            //    StringComparison.InvariantCultureIgnoreCase))
            if ((actionDescriptor.ControllerDescriptor.ControllerName == "Product" || actionDescriptor.ControllerDescriptor.ControllerName == "Products") &&
                actionDescriptor.ActionName.Equals("ProductList", StringComparison.InvariantCultureIgnoreCase))
            {
                if (controllerContext.RouteData.Values["area"] != null &&
                    (controllerContext.RouteData.Values["area"].ToString() == "Admin" || controllerContext.RouteData.Values["area"].ToString() == "Vendor"))
                {
                    //return new List<System.Web.Mvc.Filter>() { new System.Web.Mvc.Filter(this, FilterScope.Action, 0) };
                }
            }

            if ((actionDescriptor.ControllerDescriptor.ControllerName == "Home") &&
                actionDescriptor.ActionName.Equals("Index",
                StringComparison.InvariantCultureIgnoreCase))
            {
                return new List<System.Web.Mvc.Filter>() { new System.Web.Mvc.Filter(this, FilterScope.Action, 0) };
            }

            var a = actionDescriptor.GetCustomAttributes(true);
            var b = actionDescriptor.GetFilterAttributes(true);
            var c = actionDescriptor.GetParameters();

            return new List<System.Web.Mvc.Filter>();
        }
开发者ID:mhsohail,项目名称:Livetameion_3.7,代码行数:28,代码来源:ActionFilters.cs

示例3: GetThemedAttribute

 private static ThemedConditionalAttribute GetThemedAttribute(ActionDescriptor descriptor)
 {
     return
         descriptor.GetCustomAttributes(typeof(ThemedConditionalAttribute), true).Concat(
             descriptor.ControllerDescriptor.GetCustomAttributes(typeof(ThemedConditionalAttribute), true)).
             OfType<ThemedConditionalAttribute>().FirstOrDefault();
 }
开发者ID:ThinkPublishing,项目名称:Summit.Core,代码行数:7,代码来源:ThemeConditionalFilter.cs

示例4: LoadFilterAttributes

 private static IEnumerable<FilterAttributeMetadata> LoadFilterAttributes(ActionDescriptor actionDescriptor)
 {
     return actionDescriptor.GetCustomAttributes(typeof(IFilterAttribute), true).Cast<IFilterAttribute>().
                             Select(x => new FilterAttributeMetadata(x, FilterScope.Action)).
                             Union(actionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(IFilterAttribute), true).
                             Cast<IFilterAttribute>().
                             Select(x => new FilterAttributeMetadata(x, FilterScope.Controller)));
 }
开发者ID:skalinets,项目名称:aspmvc_vs_fubumvc,代码行数:8,代码来源:FilterAttributeProvider.cs

示例5: GetFilters

        public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            var anonymousAction = actionDescriptor.GetCustomAttributes(typeof (AllowAnonymousAttribute), false);

            if (anonymousAction.Length == 0)
            {
                yield return new Filter(DependencyResolver.Current.GetService<AuthorizationRequiredFilter>(), FilterScope.Controller, 1);
            }
            else
            {
                yield return new Filter(new FilterAttributeFilterProvider(), FilterScope.Controller, 1);
            }
        }
开发者ID:JoshuaKaminsky,项目名称:PhotographySite,代码行数:13,代码来源:FilterProvider.cs

示例6: CreateCachePolicy

        /// <summary>
        /// 创建缓存策略
        /// </summary>
        /// <param name="context">控制器上下文</param>
        /// <param name="action">Action 信息</param>
        /// <param name="parameters">Action 参数</param>
        /// <returns>缓存策略</returns>
        protected override CachePolicy CreateCachePolicy( ControllerContext context, ActionDescriptor action, IDictionary<string, object> parameters )
        {
            var httpMethod = context.HttpContext.Request.HttpMethod;
              if ( !httpMethod.EqualsIgnoreCase( "get" ) && !httpMethod.EqualsIgnoreCase( "header" ) )//如果不是GET或Header请求,都不予缓存。
            return null;

              //如果存在 Cacheable 筛选器,则不再提供默认策略。
              if ( action.GetCustomAttributes( typeof( CacheableAttribute ), true ).Any() || action.ControllerDescriptor.GetCustomAttributes( typeof( CacheableAttribute ), true ).Any() )
            return null;

              ControllerCachePolicyProvider provider = GetControllerProvider( MvcEnvironment.GetAreaName( context ), action.ControllerDescriptor.ControllerName );
              if ( provider != null )
              {
            var policy = provider.CreateCachePolicy( context, action, parameters );
            if ( policy != null )
              return policy;
              }

              return MvcEnvironment.CreateCachePolicy( context, action, parameters );
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:27,代码来源:GlobalCacheFilter.cs

示例7: GetAdminAuthorizeAttributes

 private IEnumerable<AdminAuthorizeAttribute> GetAdminAuthorizeAttributes(ActionDescriptor descriptor)
 {
     return descriptor.GetCustomAttributes(typeof(AdminAuthorizeAttribute), true)
         .Concat(descriptor.ControllerDescriptor.GetCustomAttributes(typeof(AdminAuthorizeAttribute), true))
         .OfType<AdminAuthorizeAttribute>();
 }
开发者ID:KhangTranIt,项目名称:Bluesky,代码行数:6,代码来源:AdminAuthorizeAttribute.cs

示例8: GetFilters

 /// <summary>
 /// Loads the configuration-based filters and
 /// returns them to the MVC runtime
 /// </summary>
 /// <param name="controllerCtx">
 /// The current controller
 /// </param>
 /// <param name="actionDesc">
 /// The current action
 /// </param>
 /// <returns>
 /// An enumeration of configured action filters
 /// </returns>
 public IEnumerable<System.Web.Mvc.Filter> GetFilters(
     ControllerContext controllerCtx,
     ActionDescriptor actionDesc)
 {
     String controller = actionDesc.ControllerDescriptor.ControllerName;
     String action = actionDesc.ActionName;
     return this
        .Cast<FilterElement>()
        // match the controller name or all controllers
        .Where(f =>
       String.IsNullOrEmpty(f.Controller) ||
       String.Compare(f.Controller, controller, false) == 0
        )
        // match the action name or all actions
        .Where(f =>
       String.IsNullOrEmpty(f.Action) ||
       String.Compare(f.Action, action, false) == 0
        )
        // action attributes override configured attributes
        .Where(f =>
       !actionDesc.GetCustomAttributes(f.RuntimeType, true).Any()
        )
        .Select(f => f.Filter);
 }
开发者ID:modulexcite,项目名称:NLogEx,代码行数:37,代码来源:FilterElement.cs

示例9: GetAdminAttributes

 private static IEnumerable<FrontMenuAttribute> GetAdminAttributes(ActionDescriptor descriptor)
 {
     return descriptor.GetCustomAttributes(typeof(FrontMenuAttribute), true)
         .Concat(descriptor.ControllerDescriptor.GetCustomAttributes(typeof(FrontMenuAttribute), true))
         .OfType<FrontMenuAttribute>();
 }
开发者ID:wezmag,项目名称:Coevery,代码行数:6,代码来源:FrontMenuAuthorFilter.cs

示例10: GetActionRouteFactories

 protected override IReadOnlyList<IDirectRouteFactory> GetActionRouteFactories(ActionDescriptor actionDescriptor)
 {
     return actionDescriptor.GetCustomAttributes(typeof(IDirectRouteFactory), inherit: true).Cast<IDirectRouteFactory>().ToArray();
 }
开发者ID:NickLarsen,项目名称:game-frame,代码行数:4,代码来源:IneritedDirectRouteProvider.cs

示例11: GetPermissionAuthorizationAttributes

 private IEnumerable<PermissionAuthorizationAttribute> GetPermissionAuthorizationAttributes(ActionDescriptor descriptor)
 {
     return descriptor.GetCustomAttributes(typeof(PermissionAuthorizationAttribute), true)
         .Concat(descriptor.ControllerDescriptor.GetCustomAttributes(typeof(PermissionAuthorizationAttribute), true))
         .OfType<PermissionAuthorizationAttribute>();
 }
开发者ID:netsouls,项目名称:eCentral,代码行数:6,代码来源:PermissionAuthorizationAttribute.cs

示例12: GetFilters

		public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
		{
			DVSAuthorizeFilterAttribute controllerAttribute = (DVSAuthorizeFilterAttribute)controllerContext.Controller.GetType().GetCustomAttributes(true).FirstOrDefault(e => e.GetType() == typeof(DVSAuthorizeFilterAttribute));
			DVSAuthorizeFilterAttribute actionAttribute = (DVSAuthorizeFilterAttribute)actionDescriptor.GetCustomAttributes(true).FirstOrDefault(e => e.GetType() == typeof(DVSAuthorizeFilterAttribute));
			if (actionAttribute != null)
			{
				actionAttribute.AccessHelper = _kernel.Get<IUserAccessHelper>();
				return new[] { new Filter(actionAttribute, FilterScope.Action, 1) };
			}
			if (controllerAttribute != null)
			{
				controllerAttribute.AccessHelper = _kernel.Get<IUserAccessHelper>();
				return new[] { new Filter(controllerAttribute, FilterScope.Controller, 1) };
			}
			return Enumerable.Empty<Filter>();
		}
开发者ID:evkap,项目名称:DVS,代码行数:16,代码来源:DVSAuthorizeFilterAttribute.cs

示例13: GetAuthorizationMode

		internal static AuthorizationMode GetAuthorizationMode(ActionDescriptor actionDescriptor, System.Web.Routing.RequestContext requestContext, out string schemaId, out string actionId, out ICredentialValidator validator)
		{
			schemaId = null;
			actionId = null;
			validator = null;

			//查找位于Action方法的授权标记
			var attribute = (AuthorizationAttribute)actionDescriptor.GetCustomAttributes(typeof(Zongsoft.Security.Membership.AuthorizationAttribute), true).FirstOrDefault();

			if(attribute == null)
			{
				//查找位于Controller类的授权标记
				attribute = (AuthorizationAttribute)actionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(Zongsoft.Security.Membership.AuthorizationAttribute), true).FirstOrDefault();

				if(attribute == null)
					return AuthorizationMode.Disabled;

				validator = attribute.Validator;

				if(attribute.Mode == AuthorizationMode.Required)
				{
					schemaId = string.IsNullOrWhiteSpace(attribute.SchemaId) ? GetSchemaId(actionDescriptor.ControllerDescriptor.ControllerName, requestContext.RouteData.Values["area"] as string) : attribute.SchemaId;
					actionId = actionDescriptor.ActionName;
				}

				return attribute.Mode;
			}

			validator = attribute.Validator;

			if(attribute.Mode != AuthorizationMode.Required)
				return attribute.Mode;

			schemaId = attribute.SchemaId;
			actionId = string.IsNullOrWhiteSpace(attribute.ActionId) ? actionDescriptor.ActionName : attribute.ActionId;

			if(string.IsNullOrWhiteSpace(schemaId))
			{
				var controllerAttribute = (AuthorizationAttribute)Attribute.GetCustomAttribute(actionDescriptor.ControllerDescriptor.ControllerType, typeof(Zongsoft.Security.Membership.AuthorizationAttribute), true);

				if(controllerAttribute == null || string.IsNullOrWhiteSpace(controllerAttribute.SchemaId))
					schemaId = GetSchemaId(actionDescriptor.ControllerDescriptor.ControllerName, requestContext.RouteData.Values["area"] as string);
				else
					schemaId = controllerAttribute.SchemaId;
			}

			return attribute.Mode;
		}
开发者ID:Flagwind,项目名称:Zongsoft.Web,代码行数:48,代码来源:AuthenticationUtility.cs

示例14: GetAuthorizationAttribute

		internal static AuthorizationAttribute GetAuthorizationAttribute(ActionDescriptor actionDescriptor)
		{
			//查找位于Action方法的授权标记
			var attribute = (AuthorizationAttribute)actionDescriptor.GetCustomAttributes(typeof(Zongsoft.Security.Membership.AuthorizationAttribute), true).FirstOrDefault();

			if(attribute == null)
			{
				//查找位于Controller类的授权标记
				attribute = (AuthorizationAttribute)actionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(Zongsoft.Security.Membership.AuthorizationAttribute), true).FirstOrDefault();
			}

			return attribute;
		}
开发者ID:Flagwind,项目名称:Zongsoft.Web,代码行数:13,代码来源:AuthenticationUtility.cs

示例15: GetAuthorizeAttributes

 protected virtual IEnumerable<AuthorizeAttribute> GetAuthorizeAttributes(ActionDescriptor actionDescriptor, ControllerContext controllerContext)
 {
     return actionDescriptor.GetCustomAttributes(typeof(AuthorizeAttribute), true).OfType
                    <AuthorizeAttribute>().ToList()
                    .Union(
                        actionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(AuthorizeAttribute), true).OfType
                            <AuthorizeAttribute>().ToList());
 }
开发者ID:agrynco,项目名称:MvcSiteMapProvider,代码行数:8,代码来源:AuthorizeAttributeAclModule.cs


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