2016年5月12日我的第一个播客

复制代码
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 
 7 namespace lizhugz.Areas.lizhuAdmin.Models
 8 {
 9     public class FilterAttribute:ActionFilterAttribute
10     {
11         /* Filter
12          * 体验AOP编程思想
13          Result:视图
14          Ation:方法
15          用[FilterAttribute]调用
16          放在控制器前:该控制器下所有方法经过这个验证
17          放在方法前:该方法使用这个验证
18          */
19          public string Message { get; set; }
20 
21         //在Action执行之后执行
22         public override void OnActionExecuted(ActionExecutedContext filterContext)
23         {
24            
25             base.OnActionExecuted(filterContext);   
26         }
27 
28         //在Action执行之前执行
29         public override void OnActionExecuting(ActionExecutingContext filterContext)
30         {
31             if (HttpContext.Current.Session["userId"]==null)
32             {
33                 
34                 HttpContext.Current.Response.Redirect("/lizhuAdmin/AdeminProData/Login");
35             }
36             else
37             {
38                 HttpContext.Current.Response.Redirect("/lizhuAdmin/AdeminProData/Index");
39             }
40            
41                 
42                 base.OnActionExecuting(filterContext);
43           
44             
45         }
46 
47         //在Result执行之后执行
48         public override void OnResultExecuted(ResultExecutedContext filterContext)
49         {
50             base.OnResultExecuted(filterContext);
51         }
52 
53         //在Result执行之前
54         public override void OnResultExecuting(ResultExecutingContext filterContext)
55         {
56             base.OnResultExecuting(filterContext);  
57         }
58     }
59 
60 
61     
62 }
View Code
复制代码

 

posted @   君宁天下  阅读(170)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
野生程序员真的是太难了,一刻也不敢停止学习
点击右上角即可分享
微信分享提示