你怎么能得到的"真正的" HttpContext的ASP.NET MVC应用程序中? [英] How can you get the "real" HttpContext within an ASP.NET MVC application?

查看:101
本文介绍了你怎么能得到的"真正的" HttpContext的ASP.NET MVC应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我必须这样做。我使用ELMAH为我的错误日志。我的路线我error.aspx观点之前,我必须抓住默认ELMAH错误日志,所以我可以记录异常。你以前可以使用

Unfortunately, I need to do this. I'm using ELMAH for my error log. Before I route to my error.aspx view, I have to grab the default ELMAH error log so I can log the exception. You used to be able to use

Elmah.ErrorLog.Default

然而,这是现在被标记为过时。编译器指示我使用的方法

However, this is now marked as obsolete. The compiler directs me to use the method

Elmah.ErrorLog.GetDefault(HttpContext context)

MVC的上下文类型HttpContextBase的,这使我们能够模拟它(耶!)。我们如何应对需要老式的HttpContext?

MVC's context is of type HttpContextBase, which enables us to mock it (YAY!). How can we deal with MVC-unaware libraries that require the old style HttpContext?

推荐答案

尝试 System.Web.HttpContext.Current 。它应该做的伎俩。

Try System.Web.HttpContext.Current. It should do the trick.

获取有关个人的HTTP请求的HTTP特定信息。

Gets HTTP-specific information about an individual HTTP request.

<一个href=\"https://msdn.microsoft.com/en-us/library/system.web.httpcontext.current%28v=vs.110%29.aspx\">MSDN

这篇关于你怎么能得到的&QUOT;真正的&QUOT; HttpContext的ASP.NET MVC应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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