im trying to access the httpcontext.current
but 开发者_如何学编程i can't. I usually can do like HttpContext.Current.User.Identity;
but now its directly like HttpContext.User.Identity;
or HttpContext.Response.Cookies
to me it does not matter aslong as it works but im just qurious
In that respect, no it has not changed (but it has changed in many other ways).
If you are using MVC, HttpContext
in a controller without a namespace prefix refers to a property on the Controller, not the class.
So you should be able to use:
System.Web.HttpContext.Current
Or, in MVC, a shortcut would just be HttpContext
which is a wrapper around HttpContext.Current
.
Where are you trying to access the HttpContext from?
If you're using ASP.NET MVC and trying to acces it from an Action for example. there's a property on 'System.Web.Mvc.Controller' named HttpContext which returns an instance of HttpContextBase, wich is probably what you're looking for.
This property is the preferred way to access the HTTP context.
Because the class name is the same as the property name, the property is used instead of the class.
If you really want to access the HttpContext through the static property of the HttpContext class, you can still do it like this:
System.Web.HttpContext.Current.User.Identity
精彩评论