开发者

has the httpcontext changed with .net 4.0?

开发者 https://www.devze.com 2023-04-03 09:01 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消