public override void OnActionExecuting(FilterExecutingContext filterContext) { //redirect if the user is not authenticated if (!String.IsNullOrEmpty(RoleToCheckFor)) { if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { // my simple Version filterContext.HttpContext.Response.Redirect("~/Login"); // Robs "better" Version //use the current url for the redirect //string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath; //send them off to the login page //string redirectUrl = string.Format("?ReturnUrl={0}", redirectOnSuccess); //string loginUrl = FormsAuthentication.LoginUrl + redirectUrl; //filterContext.HttpContext.Response.Redirect(loginUrl, true); } else { bool isAuthorized = filterContext.HttpContext.User.IsInRole(this.RoleToCheckFor); if (!isAuthorized) { throw new UnauthorizedAccessException("You are not authorized to view this page"); } } } else { throw new InvalidOperationException("No Role Specified"); } }
public override void OnActionExecuting(FilterExecutingContext filterContext) { //redirect if the user is not authenticated if (!String.IsNullOrEmpty(RoleToCheckFor)) { if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { // my simple Version filterContext.HttpContext.Response.Redirect("~/Login"); // Robs "better" Version //use the current url for the redirect //string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath; //send them off to the login page //string redirectUrl = string.Format("?ReturnUrl={0}", redirectOnSuccess); //string loginUrl = FormsAuthentication.LoginUrl + redirectUrl; //filterContext.HttpContext.Response.Redirect(loginUrl, true); } else { bool isAuthorized = filterContext.HttpContext.User.IsInRole(this.RoleToCheckFor); if (!isAuthorized) throw new UnauthorizedAccessException("You are not authorized to view this page"); } } else { throw new InvalidOperationException("No Role Specified"); } }
public override void OnActionExecuting(FilterExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; Controller controller = filterContext.Controller as Controller; if (controller != null) { if (session["Login"] == null) { filterContext.Cancel = true; controller.HttpContext.Response.Redirect("./Login"); } } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(FilterExecutingContext filterContext) { //redirect if not authenticated if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { // my simple Version filterContext.HttpContext.Response.Redirect("~/Login"); // Robs "better" Version //use the current url for the redirect //string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath; //send them off to the login page //string redirectUrl = string.Format("?ReturnUrl={0}", redirectOnSuccess); //string loginUrl = FormsAuthentication.LoginUrl + redirectUrl; //filterContext.HttpContext.Response.Redirect(loginUrl, true); } }
public override void OnActionExecuting(FilterExecutingContext filterContext) { HttpSessionStateBase session = filterContext.HttpContext.Session; Controller controller = filterContext.Controller as Controller; if (controller != null) { if (session != null && session ["authstatus"] == null) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Login" }, { "action", "Index" } }); } } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(FilterExecutingContext filterContext) { //redirect if not authenticated if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { // my simple Version filterContext.HttpContext.Response.Redirect("~/Login"); // Robs "better" Version //use the current url for the redirect //string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath; //send them off to the login page //string redirectUrl = string.Format("?ReturnUrl={0}", redirectOnSuccess); //string loginUrl = FormsAuthentication.LoginUrl + redirectUrl; //filterContext.HttpContext.Response.Redirect(loginUrl, true); } }
public override void OnActionExecuting(FilterExecutingContext filterContext) { if (filterContext.Controller is ControllerBase) { var b = filterContext.Controller as ControllerBase; if (b != null) { if (b.HttpContext.Session["RoleList"] != null) { roleList = b.HttpContext.Session["RoleList"].ToString().Split(new Char[] { ',' }); } else { //Session超时退出 b.RedirectToAction("messagepage", "admin"); } bool flag = false; for (int i = 0; i < roleList.Count(); i++) { //超级管理员具有所有权限 if (roleList[i] == "超级管理员" || _RoleName == roleList[i]) { flag = true; break; } } if (flag != true) { filterContext.Cancel = true; b.RedirectToAction("AccessDenied", "Security"); } //原来的代码 //if (!b.User.IsInRole(_RoleName)) //{ // filterContext.Cancel = true; // b.RedirectToAction("AccessDenied", "Security"); //} } } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(FilterExecutingContext filterContext) { if (filterContext.Controller is ControllerBase) { var b = filterContext.Controller as ControllerBase; if (b != null) { //if (b.HttpContext.Session["RoleList"] == null) //{ // //Session超时退出 // b.RedirectToAction("messagepage", "admin"); //} if (!b.User.Identity.IsAuthenticated && b.HttpContext.Session["RoleList"] == null) { filterContext.Cancel = true; b.RedirectToAction("messagepage", "admin"); //FormsAuthentication.RedirectToLoginPage(); } } } base.OnActionExecuting(filterContext); }
public override void OnActionExecuting(FilterExecutingContext filterContext) { CQGJEntities CQGJ = new CQGJEntities(); if (filterContext.Controller is ControllerBase) { var b = filterContext.Controller as ControllerBase; if (b != null) { string ip = b.HttpContext.Request.UserHostAddress; string url = b.HttpContext.Request.RawUrl; string refer = b.HttpContext.Request.UrlReferrer.OriginalString; //Uri u = b.HttpContext.Request.UrlReferrer; DateTime temp = DateTime.Now.AddDays(-1); var query = from s in CQGJ.Statistic where s.IP == ip && s.AddTime.Value >= temp select s; if (query.Count() >= 1) { Statistic statistic = query.First(); statistic.LocalUrl = url; statistic.ReferingUrl = refer; statistic.UpdateTime = DateTime.Now; CQGJ.SaveChanges(); } else { Statistic statistic = new Statistic(); statistic.Hits = 1; statistic.ReferingUrl = refer; statistic.LocalUrl = url; statistic.IP = ip; statistic.AddTime = DateTime.Now; CQGJ.AddToStatistic(statistic); CQGJ.SaveChanges(); } } } base.OnActionExecuting(filterContext); }