开发者

MVC3- ASP.NET-Logged In Person-Different Methods

开发者 https://www.devze.com 2023-03-07 01:24 出处:网络
I wa开发者_JAVA技巧nt to find out the logged in person What is the Difference between the following.

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).

0

精彩评论

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