.net 标准库中的 HttpContext [英] HttpContext in .net standard library
问题描述
我正在开发几个项目,其中一个是 ASP.NET 4.5
应用程序,另一个是 .Net Core API 1.1
项目.asp.net 应用程序使用 HttpContext
类来读取 cookie 和页眉.现在,我需要将它移动到一个 .net 标准库,该库可以被两个项目使用.我在 .net 标准 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.net application is using HttpContext
classes to read cookies and page headers. Now, I need to move this to a .net standard library which can be used by both the project. I don't find HttpContext in .net standard SDK. Any suggestions?
推荐答案
你的方法有一个问题:.NET Standard 是 .NET 最简单的实现,这意味着只有平台和场景的基本功能-agnostic 已实现.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.
所以,你有三个选择:
- 面向 .NET Framework 并使用
System.Web.HttpContext
- 面向 .NET Core 并使用
Microsoft.AspNetCore.Http.HttpContext
- 将使用
HttpContext
的逻辑从 .NET Standard 项目中移开
- Target the .NET Framework and use
System.Web.HttpContext
- Target .NET Core and use
Microsoft.AspNetCore.Http.HttpContext
- Move the logic that uses
HttpContext
away from the .NET Standard project
但是请注意,这些类差异很大..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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!