在ASP.NET MVC之间HttpContext.Current和Controller.Context差异

编程入门 行业动态 更新时间:2024-10-17 00:24:45
本文介绍了在ASP.NET MVC之间HttpContext.Current和Controller.Context差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我工作的一个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差异

本文发布于:2023-11-13 15:02:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:差异   MVC   NET   ASP   HttpContext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!