HttpContext.Current not Resolving in MVC 4 Project

荒凉一梦 提交于 2019-11-30 06:05:53

The problem is that the Controller class has a public property called HttpContext (see http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.httpcontext.aspx).

This means that when you attempt to use it without any qualification in the controller it resolves to the local property and not System.Web.HttpContext. The type of the property is HttpContextBase which does have a Request property that would do what you want (though note that it isn't the same class as you would get from System.Web.HttpContext.

user2343180

Try prefixing it with System.Web.

If I try System.Web.HttpContext.Current, then Current is there, but if I try HttpContext.Current, then it doesn't recognize 'Current'. I do have System.Web in my using statements, but I still seem to be required to specify it in order to get access to 'Current'.

Very simple add library

using System.Web;

and replace

context.Response -> HttpContext.Current.Response

means

context -> HttpContext.Current

and your problem is solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!