I wa开发者_JAVA技巧nt to find out the logged in person
What is the Difference between the following.
string loggedInName = HttpContext.User.Identity.Name.ToString();
string loggedInName = HttpContext.Current.User.Identity.Name.ToString();
I am asking this question because I cannot use the Second one in Controller. It gives the following Error
System.Web.HttpContextBase' does not contain a definition for 'Current' and no extension method 'Current' accepting a first argument of type 'System.Web.HttpContextBase' could be found (are you missing a using directive or an assembly reference?)
They are identical only if you're not working with threads; System.Web.HttpContext.Current contains the value which is tied to the thread. That is, in any additional thread, you cannot access HttpContext.Current.
HttpContext.Current is a static method that return the current http context, while Context is an instance method defined in the page class that returns the current http context (it really just calls the above function).
精彩评论