OnActionExecuted 获取状态码 [英] OnActionExecuted get status code

查看:33
本文介绍了OnActionExecuted 获取状态码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 OnActionExecuted 的 MVC 操作中获取 HTTP 状态代码,而不使用会话变量?

Is there a way to get the HTTP status code from MVC action from OnActionExecuted, without using the session variables?

推荐答案

有几种方法可以访问它.主要通过继承自 ControllerContext

There are a few ways to access it. Mainly via the ActionExecutedContext which inherits from ControllerContext

protected override void OnActionExecuted(ActionExecutedContext filterContext) {
    var statusCode = filterContext.HttpContext.Response.StatusCode;
}

这篇关于OnActionExecuted 获取状态码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆