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需要配置成你的登陆页面的路径。
西安.NET俱乐部群
![西安.NET俱乐部群](https://images.cnblogs.com/cnblogs_com/Flyear/778713/o_1452741964368.png)