NET标准库中的HttpContext

编程入门 行业动态 更新时间:2024-10-27 06:20:37
本文介绍了NET标准库中的HttpContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在从事几个项目,其中一个是 ASP.NET 4.5 应用程序,另一个是 .Net Core API 1.1

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 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

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

    发布评论

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

    >www.elefans.com

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