asp.net-mvc – 控制器的实例上的HttpContext在ASP.net MVC中为n
发布时间:2020-12-15 18:55:47 所属栏目:asp.Net 来源:网络整理
导读:这可能不是正确的方法使用控制器,但我没有注意到这个问题,并没有想出一种方法来纠正它。 public JsonResult SomeControllerAction() { //The current method has the HttpContext just fine bool currentIsNotNull = (this.HttpContext == null); //which
这可能不是正确的方法使用控制器,但我没有注意到这个问题,并没有想出一种方法来纠正它。
public JsonResult SomeControllerAction() { //The current method has the HttpContext just fine bool currentIsNotNull = (this.HttpContext == null); //which is false //creating a new instance of another controller SomeOtherController controller = new SomeOtherController(); bool isNull = (controller.HttpContext == null); // which is true //The actual HttpContext is fine in both bool notNull = (System.Web.HttpContext.Current == null); // which is false } 我注意到控制器上的HttpContext不是“实际的”HttpContext,你会发现System.Web.HttpContext.Current。 有没有办法手动填充控制器上的HttpContextBase?或者更好的方法来创建一个Controller的实例? 解决方法
控制器的设计不是像你一样手动创建。听起来像你真正应该做的是把任何可重用的逻辑你有一个帮助类,而不是。
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 在实现URL路由时阻止对.ASPX页面的正常请求
- asp.net – 通过代码隐藏结果??在错误类型(System.Web.UI.H
- asp.net-mvc-3 – 复杂类型的可选[必需]
- asp.net-mvc-3 – 与ASP.NET MVC 3中的视图页面不同的模型的
- asp.net – 使用冗长的服务器进程取消asynch回发
- asp.net – 在.NET 4.5 Azure部署中找不到编译器可执行文件
- ASP.NET中的相对路径
- asp.net – 当页面在iFrame中时,会话变量不会保存
- ASP.NET表单身份验证 – 在调试时使用测试帐户自动登录?
- asp.net-mvc – POST数据中不包含MVC 3远程验证表单按钮
推荐文章
站长推荐
热点阅读