Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between HttpContext.Current and Controller.Context in MVC ASP.NET

Tags:

asp.net-mvc

I am working on an MVC ASP .NET application. I am relatively new to both.

In a controller I am trying to get the current log on user, for which there seem to be two ways of doing this:

System.Web.HttpContext.Current.User.Identity.Name 

Or

HttpContext.User.Identity.Name 

What is the difference between these? As far as a I can tell within the MVC framework the controller has the current HttpContext stored as a property so these methods are identical. Is that correct?

like image 391
TonE Avatar asked Apr 24 '09 11:04

TonE


1 Answers

Yes, they will usually be identical. However, if you're working with additional threads, they will not be; System.Web.HttpContext.Current is threadstatic.

like image 179
Lucero Avatar answered Oct 02 '22 00:10

Lucero