.met mvc 一种判断是否已登录的方式

 

 controller都继承于自定义的一个controller的基类,在此基类上实施切片操作。

 

 

namespace mv13.Controllers
{
public class LoginController : Controller
{
//
// GET: /Login/

public string Login()
{
HttpContext.Session["username"] = "yang";
return "hello";
}

}
}

namespace mv13.Controllers
{
public class AuthenticationController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.HttpContext.Session["username"] == null)
filterContext.Result = new RedirectToRouteResult("Default", new RouteValueDictionary( new{ action = "Login" ,controller="Login"} ));

base.OnActionExecuting(filterContext);
}

}
}

 public class HomeController : AuthenticationControllerhttp://www.cnblogs.com/qq731109249/p/3500492.html

 

posted @ 2016-07-06 21:00  朽木可雕否  阅读(173)  评论(0编辑  收藏  举报