[AttributeUsage(AttributeTargetsClass AllowMultiple = false Inherited = true)]
public sealed class SessionStateAttribute : Attribute
{
public SessionStateAttribute(SessionStateBehavior behavior)
public SessionStateBehavior Behavior { get; }
}
DefaultControllerFactory会试着获取应用在Controller类型上的SessionStateAttribute特性如果这样的特性存在则直接返回它的Behavior属性所表示的SessionStateBehavior枚举如果不存在则返回SessionStateBehaviorDefault具体的逻辑也反映在我们自定义的ReflectedControllerFactory的GetControllerSessionBehavior方法中
public class ReflectedControllerFactory : IControllerFactory
{
//其他成员
public SessionStateBehavior GetControllerSessionBehavior(
RequestContext requestContext string controllerName)
{
Type controllerType = thisGetControllerType(requestContextRouteData
controllerName)
if (null == controllerType)
{
return SessionStateBehaviorDefault;
}
SessionStateAttribute attribute = controllerType
GetCustomAttributes(true)OfType<SessionStateAttribute>()
FirstOrDefault()
attributeattribute = attribute ??
new SessionStateAttribute(SessionStateBehaviorDefault)
return attributeBehavior;
}
}
返回目录ASPNET MVC 框架揭秘
编辑推荐
ASP NET开发培训视频教程
Microsoft NET框架程序设计视频教程
Java程序性能优化让你的Java程序更快更稳定
Visual C++音频/视频技术开发与实战
[] []