Use ActionFilterAttribute to check user logging
2012-04-11 23:50
267 查看
public class CheckLoginAttribute : ActionFilterAttribute { public CheckLoginAttribute() { } public override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContext.HttpContext.Session["User"] == null) { filterContext.Result = new RedirectResult("/Account/LogOn"); return; } base.OnActionExecuting(filterContext); } }
public class HomeController : Controller { public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; return View(); } [CheckLogin] public ActionResult About() { return View(); } }
ref: MSDN
相关文章推荐
- How to use Asp.Net Mvc ActionFilterAttribute for form authentication
- ASP.NET MVC ActionFilterAttribute的执行顺序
- 插入mysql语句报错:1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
- How to use .netrc file on windows to save user and password
- Call requires permission which may be rejected by user: code should explicitly check to see if permi
- ASP.NET MVC 利用ActionFilterAttribute来判断用户是否登陆等等
- MVC权限验证之ActionFilterAttribute
- Jenkins部署:The username you provided is not allowed to use the text-based Tomcat Manager (error 403)
- How to use the windows active directory to authenticate user via logon form 如何自定义权限系统,使用 active directory验证用户登录
- check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYP
- 出现Form action defaulting to 'action' attribute's literal value 警告的原因
- The username you provided is not allowed to use the text-based Tomcat Manager (error 403)
- How to use authority check
- CHECK the manual that corresponds TO your MySQL SERVER VERSION FOR the RIGHT syntax TO USE near.....
- guard class ,can extend to debug by add errorline number when use this check
- Java Runtime error: java.lang.NoSuchMethodError: CheckUserActivity.getActionBar
- Part 68 - What is the use of NonAction attribute in mvc
- 使用ActionFilterAttribute 记录 WebApi Action 请求和返回结果记录
- ActionFilterAttribute做切面编程的Url的格式化例子
- check the manual that corresponds to your MySQL server version for the right syntax to use near