本文整理汇总了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);
}
示例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>();
}
示例3: GetThemedAttribute
private static ThemedConditionalAttribute GetThemedAttribute(ActionDescriptor descriptor)
{
return
descriptor.GetCustomAttributes(typeof(ThemedConditionalAttribute), true).Concat(
descriptor.ControllerDescriptor.GetCustomAttributes(typeof(ThemedConditionalAttribute), true)).
OfType<ThemedConditionalAttribute>().FirstOrDefault();
}
示例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)));
}
示例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);
}
}
示例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 );
}
示例7: GetAdminAuthorizeAttributes
private IEnumerable<AdminAuthorizeAttribute> GetAdminAuthorizeAttributes(ActionDescriptor descriptor)
{
return descriptor.GetCustomAttributes(typeof(AdminAuthorizeAttribute), true)
.Concat(descriptor.ControllerDescriptor.GetCustomAttributes(typeof(AdminAuthorizeAttribute), true))
.OfType<AdminAuthorizeAttribute>();
}
示例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);
}
示例9: GetAdminAttributes
private static IEnumerable<FrontMenuAttribute> GetAdminAttributes(ActionDescriptor descriptor)
{
return descriptor.GetCustomAttributes(typeof(FrontMenuAttribute), true)
.Concat(descriptor.ControllerDescriptor.GetCustomAttributes(typeof(FrontMenuAttribute), true))
.OfType<FrontMenuAttribute>();
}
示例10: GetActionRouteFactories
protected override IReadOnlyList<IDirectRouteFactory> GetActionRouteFactories(ActionDescriptor actionDescriptor)
{
return actionDescriptor.GetCustomAttributes(typeof(IDirectRouteFactory), inherit: true).Cast<IDirectRouteFactory>().ToArray();
}
示例11: GetPermissionAuthorizationAttributes
private IEnumerable<PermissionAuthorizationAttribute> GetPermissionAuthorizationAttributes(ActionDescriptor descriptor)
{
return descriptor.GetCustomAttributes(typeof(PermissionAuthorizationAttribute), true)
.Concat(descriptor.ControllerDescriptor.GetCustomAttributes(typeof(PermissionAuthorizationAttribute), true))
.OfType<PermissionAuthorizationAttribute>();
}
示例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>();
}
示例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;
}
示例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;
}
示例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());
}