无法访问 .net 标准中的 httpcontext 扩展方法 [英] Can't access httpcontext extension methods in .net standard
问题描述
我有这个 .NET Standard 库,我想在其中编写 .NET Core 中间件.
I have this .NET Standard library where I want to write a .NET Core middleware.
里面我想做的:
Endpoint endpoint = httpContext.GetEndpoint();
无法解析GetEndpoint()
扩展方法.
我已经引用了 Microsoft.AspNetCore.Http
并且我同时拥有 Microsoft.AspNetCore.Http.Abstractions
和 Microsoft.AspNetCore.Mvc.Core
添加到项目中的包.
I have referenced Microsoft.AspNetCore.Http
and I have both Microsoft.AspNetCore.Http.Abstractions
and Microsoft.AspNetCore.Mvc.Core
packages added to the project.
有没有办法解决这个问题,我是否遗漏了什么?
Is there a solution to this, am I missing something?
推荐答案
我假设您正在为 ASP.NET Core 3.1 编写中间件,因为您包含了asp.net-core-3.1"标签.
I assume you're writing a middleware for ASP.NET Core 3.1 since you included the "asp.net-core-3.1" tag.
要使用该扩展,您需要针对 netcoreapp3.*
而不是 netstandard2.*
:
To use that extension, you need to target netcoreapp3.*
instead of netstandard2.*
:
<TargetFramework>netcoreapp3.1</TargetFramework>
(您可以在 文档 页面)
您还需要:
- 使用
Microsoft.NET.Sdk.Web
MSBuild SDK:
- use the
Microsoft.NET.Sdk.Web
MSBuild SDK:
<Project Sdk="Microsoft.NET.Sdk.Web">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
这篇关于无法访问 .net 标准中的 httpcontext 扩展方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!