| 特性 | 描述 |
|---|---|
| ActionNameAttribute | 定义Action的名称(可以和Action方法名不同) |
| AcceptVerbsAttribute | 定义支持的Http Method名称,支持单个或多个Method。 |
| ActivateAttribute | 依赖注入的标记,可以放在具有set权限的属性或字段上。 |
| ResponseCacheAttribute | 针对某个Controller或Action设置客户端缓存。 |
| RequireHttpsAttribute | 限制必须是Https请求。 |
| RemoteAttribute | 标记为Ajax请求,服务器端不验证form表单的验证。 |
| NonControllerAttribute | 标记该类不是Controller。 |
| NonActionAttribute | 标记该方法不是Action。 |
Microsoft.AspNet.Mvc Microsoft.AspNet.Mvc.Core Microsoft.AspNet.Mvc.ModelBinding Microsoft.AspNet.Mvc.Razor Microsoft.AspNet.Mvc.Razor.Host Microsoft.AspNet.Mvc.TagHelpers Microsoft.AspNet.Mvc.Xml Microsoft.AspNet.PageExecutionInstrumentation.Interfaces
public interface IAssemblyProvider
{
IEnumerable<Assembly> CandidateAssemblies { get; }
}
services.AddMvc().WithControllersAsServices(new[]
{
typeof(MyController).Assembly,
typeof(ExternalPocoController).Assembly
});
var col = this.Resolver.GetRequiredService<ILibraryManager>();
var data = col.GetReferencingLibraries("Microsoft.AspNet.Mvc");
protected virtual IEnumerable<ILibraryInformation> GetCandidateLibraries()
{
if (ReferenceAssemblies == null)
{
return Enumerable.Empty<ILibraryInformation>();
}
// GetReferencingLibraries returns the transitive closure of referencing assemblies
// for a given assembly.
return ReferenceAssemblies.SelectMany(_libraryManager.GetReferencingLibraries)
.Distinct()
.Where(IsCandidateLibrary);
}
public interface IControllerTypeProvider
{
IEnumerable<TypeInfo> ControllerTypes { get; }
}
protected internal virtual bool IsController([NotNull] TypeInfo typeInfo,
[NotNull] ISet<Assembly> candidateAssemblies)
{
if (!typeInfo.IsClass) // 该类型必须是一个类
{
return false;
}
if (typeInfo.IsAbstract) // 该类必须不是抽象类
{
return false;
}
// We only consider public top-level classes as controllers. IsPublic returns false for nested
// classes, regardless of visibility modifiers
if (!typeInfo.IsPublic) // 该类必须是一个Public类(并且不嵌套),嵌套类不能作为Controller
{
return false;
}
if (typeInfo.ContainsGenericParameters) // 该类不能是泛型类
{
return false;
}
if (!typeInfo.Name.EndsWith(ControllerTypeName, StringComparison.OrdinalIgnoreCase) &&
!DerivesFromController(typeInfo, candidateAssemblies)) // 该类以Controller结尾,或继承于Controller基类,或其父类也是Controller。
{
return false;
}
if (typeInfo.IsDefined(typeof(NonControllerAttribute))) // 该类不能设置NonControllerAttribute特性
{
return false;
}
return true;
}
services.AddMvc().WithControllersAsServices(new[]
{
typeof(MyController),
typeof(ExternalPocoController)
});
public Task<ActionDescriptor> SelectAsync([NotNull] RouteContext context)
{
// ...
}
public IEnumerable<ActionModel> BuildActionModels([NotNull] TypeInfo typeInfo,
[NotNull] MethodInfo methodInfo)
{
if (!IsAction(typeInfo, methodInfo))
{
return Enumerable.Empty<ActionModel>();
}
// ....省略其它代码
}
protected virtual bool IsAction([NotNull] TypeInfo typeInfo, [NotNull] MethodInfo methodInfo)
{
// The SpecialName bit is set to flag members that are treated in a special way by some compilers
// (such as property accessors and operator overloading methods).
if (methodInfo.IsSpecialName) // 不能是特殊名称(如重载的操作符或属性访问器)
{
return false;
}
if (methodInfo.IsDefined(typeof(NonActionAttribute))) // 不能声明NonActionAttribute特性
{
return false;
}
// Overriden methods from Object class, e.g. Equals(Object), GetHashCode(), etc., are not valid.
if (methodInfo.GetBaseDefinition().DeclaringType == typeof(object)) //不能是重载的方法,比如Equals和GetHashCode
{
return false;
}
// Dispose method implemented from IDisposable is not valid
if (IsIDisposableMethod(methodInfo, typeInfo)) // 不能是Dispose方法
{
return false;
}
if (methodInfo.IsStatic) // 不能是静态方法
{
return false;
}
if (methodInfo.IsAbstract) // 不能是抽象方法
{
return false;
}
if (methodInfo.IsConstructor) // 不能是构造函数
{
return false;
}
if (methodInfo.IsGenericMethod) // 不能是泛型方法
{
return false;
}
return
methodInfo.IsPublic; // 必须是Public方法
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有