简体   繁体   English

HttpContext.Request 和 Request a .NET Core controller 有什么区别?

[英]What is the Difference between HttpContext.Request and Request a .NET Core controller?

There are similar questions but they pertain to the legacy .NET Framework.类似问题,但它们与旧版 .NET 框架有关。 This question is about the .NET Core.这个问题是关于 .NET 核心的。

What is the difference between the two statements below when executed in a controller that inherits from ControllerBase:在继承自 ControllerBase 的 controller 中执行时,以下两条语句有什么区别:

var request1 = Request;
var request2 = HttpContext.Request;

It's exactly the same instance of the object HttpRequest .它与 object HttpRequest的实例完全相同。 If you want you look the source code of ControllerBase you can see that only difference is the method to access to object.如果您想查看ControllerBase的源代码,您会发现唯一的区别是访问 object 的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM