NET标准库中的HttpContext [英] HttpContext in .net standard library

查看:248
本文介绍了NET标准库中的HttpContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事几个项目,其中一个是 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标准是.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:


  1. 定位.NET Framework并使用 System.Web.HttpContext

  2. 定位.NET Core,并使用 Microsoft.AspNetCore.Http.HttpContext

  3. 移动使用的逻辑 HttpContext 远离.NET Standard项目

  1. Target the .NET Framework and use System.Web.HttpContext
  2. Target .NET Core and use Microsoft.AspNetCore.Http.HttpContext
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆