MVC身份验证Attribute简易版

 1 public class MemberValidationAttribute : AuthorizeAttribute
 2     {
 3         protected override bool AuthorizeCore(HttpContextBase httpContext)
 4         {
 5             object user = HttpContext.Current.Session["CurrentUser"];
 6 
 7             if (user != null)
 8             {
 9                 return true;
10             }
11             return false;
12         }
13     }

另外,在web.config里面配置如下:

1 <system.web>
2  <authentication mode="Forms">
3       <forms loginUrl="~/Member/Login" timeout="2880" />
4     </authentication>
5 </system.web>

LoginUrl需要配置成你的登陆页面的路径。

posted @ 2014-10-08 10:16  人生无赖  阅读(228)  评论(0编辑  收藏  举报