我正在用 OnActionExecuting 方法写一条记录,如何获取请求的状态码
LogActionAttribute : ActionFilterAttribute
public override void OnActionExecuting(HttpActionContext filterContext)
{
_stopwatch.Stop();
var controller = filterContext.RequestContext.RouteData.Values["Controller"];
var action = filterContext.RequestContext.RouteData.Values["Action"];
var url = filterContext.Request.RequestUri;
var Method = filterContext.Request.Method;
StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream);
var statusCode = //get status code
var req_txt = reader.ReadToEnd();
var requestResponseModel = new RequestResponseModel()
{
/* Url = request.Url.LocalPath.ToString(),
Method = request.HttpMethod,
Ip = request.UserHostAddress,
RequestDate = DateTime.Now,
Expires = response.Expires,
RequestParams = req_txt,
ContentType = request.ContentType*/
};
string json = JsonConvert.SerializeObject(new { id = '2', sifre = 'c' });
//write string to file
System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/Tmp/jsondata.txt"), json);
base.OnActionExecuting(filterContext);
}