代码
using Service.IService; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace WebSiteUI.Areas.Admin.Controllers { public class AdmBaseController : Controller { public IAdminInfoManage AdminInfoManage { get; set; } protected override void OnActionExecuting(ActionExecutingContext filterContext) { //判断Session Session["AdminModel"] = model; if (filterContext.HttpContext.Session["AdminModel"] == null) { if (filterContext.HttpContext.Request.Cookies["UName"] != null) { string UName = filterContext.HttpContext.Request.Cookies["UName"].Value; string UPwd = filterContext.HttpContext.Request.Cookies["UPwd"].Value; Domain.RL_AdminInfo model = AdminInfoManage.Get(c => c.UserName == UName && c.UserPwd == UPwd); if (model != null) { filterContext.HttpContext.Session["AdminModel"] = model; } else { //跳转到登陆页 filterContext.Result = new RedirectResult("/Home/Login"); } } else { //跳转到登陆页 filterContext.Result = new RedirectResult("/Home/Login"); } } //if (filterContext.HttpContext.Request.Cookies["UserID"] == null) //{ // if (this.RouteData.Values["Controller"].ToString() != "Login") // { // //跳转到登陆页 // filterContext.Result = new RedirectResult("/Login/Index"); // } //} base.OnActionExecuting(filterContext); } } }