當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。