问题描述
我工作的一个MVC ASP .NET应用程序。我是比较新的两者。
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
或者
HttpContext.User.Identity.Name
什么是它们之间的区别?至于一个我可以MVC框架控制器具有存储为一个属性,因此这些方法是相同的当前HttpContext中说。这是否正确?
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?
推荐答案
是的,他们通常是相同的。但是,如果你有额外的线程工作,他们不会; System.Web.HttpContext.Current
是threadstatic。
Yes, they will usually be identical. However, if you're working with additional threads, they will not be; System.Web.HttpContext.Current
is threadstatic.
这篇关于在ASP.NET MVC之间HttpContext.Current和Controller.Context差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!