• mvc 过滤器


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace OAMvcApp.Models
    {
        public class LoginCheckFilterAttribute:ActionFilterAttribute
        {
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                base.OnActionExecuting(filterContext);
    
                if (filterContext.HttpContext.Session["user"] == null)
                {
                    filterContext.HttpContext.Response.Redirect("/Login/Index");
                }
            }
        }
    }

    控制器使用方法:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using OAMvcApp.Models;
    
    namespace OAMvcApp.Controllers
    {
        [LoginCheckFilterAttribute]
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                
    
                return View("win7");
            }
    
            public ActionResult About()
            {
                ViewBag.Message = "Your app description page.";
    
                return View();
            }
    
            public ActionResult Contact()
            {
                ViewBag.Message = "Your contact page.";
    
                return View();
            }
        }
    }
  • 相关阅读:
    linux文件操作
    文件和目录维护
    随心而记
    开学了
    基本逻辑门电路原理
    ubuntu搭建ftp服务
    中断
    数码管
    字,寻址和移位
    Error: Could not find or load main class resourcemanager
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/4065429.html
Copyright © 2020-2023  润新知