A MVC自定义过滤属性实现log功能(2)_.NET概论及软件使用_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

A MVC自定义过滤属性实现log功能(2)

作者:黑客防线网安ASP维护基地 来源:黑客防线网安ASP维护基地 浏览次数:0

本篇关键词:功能实现属性定义
黑客防线网安网讯:    {  LogMessage(filterContext.RouteData.Values["controller"].ToString(),  filterContext.RouteData.Values["action"].ToString(),  "Action exeuting...");  }  public vo...
    {
  LogMessage(filterContext.RouteData.Values["controller"].ToString(),
  filterContext.RouteData.Values["action"].ToString(),
  "Action exeuting...");
  }
  public void OnActionExecuted(ActionExecutedContext filterContext)
  {
  LogMessage(filterContext.RouteData.Values["controller"].ToString(),
  filterContext.RouteData.Values["action"].ToString(),
  "Action executed.");
  }
  public void OnResultExecuting(ResultExecutingContext filterContext)
  {
  LogMessage(filterContext.RouteData.Values["controller"].ToString(),
  filterContext.RouteData.Values["action"].ToString(),
  "Result executing...");
  }
  public void OnResultExecuted(ResultExecutedContext filterContext)
  {
  LogMessage(filterContext.RouteData.Values["controller"].ToString(),
  filterContext.RouteData.Values["action"].ToString(),
  "Result executed");
  }
  }
  自定义好LogMessageAttribute类应用到Controller或者action的属性在Controller 正在执行或者呈现一个View,一个HTTP请求数据时,就会在日志文件记录一些日志.
  在项目的Controller里面应用自定义的属性
  [Logging(LogName = @"D:ProjectProjectMVCProjectsky.ExtendMVCFrameworksky.ExtendMVCFrameworkLog.log")]
  public ActionResult DesplayEmployee()
  {
  ViewData["Message"] = "Our employees welcome you to our site!";
  List<Employee> employees = new List<Employee>
  {
  new Employee
  {
  FirstName="sky",
  LastName="yang",
  Email = "weflytotti@163.com",
  Department ="Development"
  },
  new Employee {
  FirstName="sky",
  LastName="yang",
  Email = "weflytotti@163.com",
  Department ="Development"
  }
  };
  return View(employees);
  }
  运行程序,正如文章开始所看到的截图!
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14441-1.html
网站维护教程更新时间:2012-03-30 05:51:04  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer