我正在从事几个项目,其中一个是 ASP.NET 4.5 应用程序,另一个是 .Net Core API 1.1 项目。 asp应用程序正在使用 HttpContext 类读取cookie和页面标题。现在,我需要将其移至两个项目都可以使用的标准库。我在标准SDK中找不到HttpContext。有什么建议吗?
I am working on couple of projects one of which is an ASP.NET 4.5 application and other one is .Net Core API 1.1 project. The asp application is using HttpContext classes to read cookies and page headers. Now, I need to move this to a standard library which can be used by both the project. I don't find HttpContext in standard SDK. Any suggestions?
推荐答案您的方法有一个问题:.NET标准是.NET的最基本的实现,意味着仅实现与平台和场景无关的基本功能。 HttpContext 在.NET Framework和.NET Core上都存在(两者顺便说一句,它实现了.NET Standard),但它特定于Web,但在.NET Standard上不存在。
There's a problem to your approach: .NET Standard is the most bare-bones implementation of .NET available, meaning that only basic features which are platform- and scenario-agnostic are implemented. HttpContext exists on both the .NET Framework and .NET Core (both of which implement .NET Standard, by the way), but being specific to the Web, it does not exist on .NET Standard.
因此,您有三个选择:
So, you have three options:
但是请注意,这些类别差异很大。 .NET Core版本是为ASP.NET Core创建的,它与ASP.NET 4.5及更早版本完全不同。
Do notice, though, that those classes vary greatly. The .NET Core version was created for ASP.NET Core which is vastly different to ASP.NET 4.5 and olders.
更多推荐
NET标准库中的HttpContext
发布评论