从ApiController内部启用IsDebuggingEnabled

本文关键字:IsDebuggingEnabled 启用 内部 ApiController | 更新日期: 2023-09-27 18:21:51

我有一个ASP.NETWebneneneba API控制器和一个public async Task<IHttpActionResult> DoThing()方法

如果不访问HttpContext.Current(该方法必须是可单元测试的),我如何确定当前请求的IsDebuggingEnabled是否为?

这些对象都没有此属性:

  • this.Request
  • this.RequestContext
  • this.ActionContext
  • this.ControllerContext

在哪里查找IsDebuggingEnabled

从ApiController内部启用IsDebuggingEnabled

HttpContext.Current.IsDebuggingEnabled

此属性实际上查看web.config配置设置,并且仅在HttpContext中查看该设置。以下方法应该有效:

var cfg =(System.Web.Configuration.CompilationSection)ConfigurationManager.GetSection("system.web/compilation");
if (cfg.Debug)
{
...
}
相关文章:
  • 没有找到相关文章