asp.net-mvc – MVC3记录请求的最佳方式
发布时间:2020-12-16 03:58:47 所属栏目:asp.Net 来源:网络整理
导读:我想记录我的MVC 3应用程序的所有请求,包括请求的URL,用户的ip地址,用户代理等.最好的地方在哪里, 1)使用基础控制器? 2)使用动作过滤器? 3)其他人? 解决方法 我在BaseController中执行此操作.像这样的东西: protected override void OnActionExecuted(Ac
我想记录我的MVC 3应用程序的所有请求,包括请求的URL,用户的ip地址,用户代理等.最好的地方在哪里,
1)使用基础控制器? 2)使用动作过滤器? 3)其他人? 解决方法
我在BaseController中执行此操作.像这样的东西:
protected override void OnActionExecuted(ActionExecutedContext filterContext) { // If in Debug mode... if (filterContext.HttpContext.IsDebuggingEnabled) { var message = string.Format(CultureInfo.InvariantCulture,"Leaving {0}.{1} => {2}",filterContext.Controller.GetType().Name,filterContext.ActionDescriptor.ActionName.Trim(),filterContext.Result); Logger.Debug(message); } // Logs error no matter what if (filterContext.Exception != null) { var message = string.Format(CultureInfo.InvariantCulture,"Exception occured {0}.{1} => {2}",filterContext.Exception.Message); Logger.Error(message); } base.OnActionExecuted(filterContext); } 希望你明白这个主意. 您还可以在执行操作之前使用以下内容进行记录: protected override void OnActionExecuting(ActionExecutingContext filterContext) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ErrorAttribute vs OnException与Applicati
- asp.net-mvc – 测量时间调用ASP.NET MVC控制器操作
- asp.net-mvc-3 – 从Razor _Layout.cshml访问Session对象
- asp.net-web-api – Xamarin.Android上的StringContent为空
- asp.net-mvc – Url.Action是编码参数值
- asp.net-mvc – 什么是强类型的视图在ASP.NET MVC
- asp.net-mvc – asp mvc home root不使用mono,fastcgi和ngi
- asp.net-mvc – ASP.NET MVC:使用EF实体作为模型?
- ASP.NET的友好URL
- prolog – 如何理解ASP中的否定失败?
推荐文章
站长推荐
- asp.net-mvc-3 – 在ASP.NET MVC3中全局访问auto
- asp.net-mvc-3 – 如何重定向到一个URL?
- asp.net-mvc – MVC错误 – 传入字典的模型项目的
- Windbg程序调试系列2-内存泄露问题
- asp.net-web-api – 如何在ConfigureServices方法
- 缩小ASP.NET应用程序的Html输出
- asp.net-mvc – 使用OWIN和WsFederation为MVC,we
- asp.net – VB.NET 2.0:代码中的URL来自哪里?
- asp.net – 无法创建页面方法“GetCompletionLis
- asp.net-mvc – 将Linq2Sql对象传递给Views有什么
热点阅读