Dejan.S
Dejan.S

Reputation: 19138

has the httpcontext changed with .net 4.0?

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

Upvotes: 0

Views: 443

Answers (2)

vcsjones
vcsjones

Reputation: 141638

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.

Upvotes: 1

Wiebe Tijsma
Wiebe Tijsma

Reputation: 10265

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

Upvotes: 0

Related Questions