• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

1、新建类customasynchresultfilterattribute继承属性,IAsyncResultFilter

ContractedBlock.gif

ExpandedBlockStart.gif

一使用微软AspNetCore。手动音量调节

2使用微软AspNetCore。Mvc。过滤

3使用项目6 .模型;

5命名空间项目6。实用过滤器

6 {

七公共类customasyncpresultfilterattribute :属性,IAsyncResultFilter

8 {

9公共customasyncpresultfilterattribute()

10 {

11控制台WriteLine('过滤器的构造函数被执行');

12 }

13

14公共异步任务OnResultExecutionAsync(ResultExecutingContext,ResultExecutionDelegate next)

15 {

16如果(上下文。结果是JsonResult)

17 {

18 JSON结果JSON结果=(JSON结果)上下文。结果;

19上下文. result=新的JSON结果(新的Ajax结果()

20 {

21成功=真,

22消息='好,

23 Data=jsonResult .价值

24 });

25 }

26

27等待下一个invoke();

28 }

29 }

30 }

查看代码

2、新建控制器CustomAsyncResultController

ContractedBlock.gif

ExpandedBlockStart.gif

一使用微软AspNetCore。手动音量调节

2使用项目6 .实用过滤器;

3

四命名空间项目6。控制器

5 {

6公共类客户异步结果控制器:控制器

7 {

8公共CustomAsyncResultController()

9 {

10控制台WriteLine('控制器的构造函数被执行');

11 }

12

13 [CustomAsyncResultFilter]

14公共行动结果索引()

15 {

16返回Json(新

17 {

18 Id=123,

19 Name='net '

20 });

21 }

22 }

23 }

查看代码

3、在各个方法开始处设置断点,运行/CustomAsyncResult

可以发现程序刚运行的时候会执行customasynchresultfilterattribute的构造方法,只执行一次,后面程序的执行顺序是

CustomAsyncResultController的构造方法-

CustomAsyncResultController的行动方法-

customasynchresultfilterattribute的OnResultExecutionAsync方法

输出结果为

{'success':true,' message':'OK ',' data':{'id':123,' name':'net'}}

在输出结果前,通过OnResultExecutionAsync方法,可以地结果进行修饰然后在输出。

Link to comment
Share on other sites