gpt4 book ai didi

asp.net-mvc - 如何在 ASP.NET Controller 中获取 'MvcApplication' 实例?

转载 作者:行者123 更新时间:2023-12-03 11:30:19 25 4
gpt4 key购买 nike

我想 MvcApplication是全局singleton .我想获取 MvcApplication 的实例在 Controller 中。然后我将以下代码放入 Controller :

MvcApplication app = HttpContext.Current.Application as MvcApplication;

它给了我一个错误:

Error 2 'System.Web.HttpContextBase' does not contain a definition for 'Current' and no extension method 'Current' accepting a first argument of type 'System.Web.HttpContextBase' could be found (are you missing a using directive or an assembly reference?)



为什么?我如何访问 MvcApplication在 Controller 中?

最佳答案

尝试这个:

var app = HttpContext.Current.ApplicationInstance as MvcApplication;

关于asp.net-mvc - 如何在 ASP.NET Controller 中获取 'MvcApplication' 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1066350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com