小编Dan*_*rne的帖子

EndpointHttpContextExtensions:.net5 中未找到 HttpContext 类扩展 (GetEndpoint)

我一直在尝试使用扩展方法 GetEndpoint() ,详细信息如下:

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.endpointhttpcontextextensions.getendpoint?view=aspnetcore-5.0

我的项目最初netstandard2.1是针对netcoreapp3.1.

无法访问 .net 标准中的 httpcontext 扩展方法

我不想以 .Net Core 3.1 为目标,因为我的项目的 Entity Framework Core 端使用最新版本中提供的功能,以 .Net Standard 2.1 为目标。

因此,我尝试以 .Net 5 为目标,看看它是否会出现,但它没有出现。我也尝试安装该软件包Microsoft.AspNetCore.Http.Abstractions但无济于事(并指出该软件包的目标是netstandard2.0)。我什至尝试将目标框架更改为netcoreapp3.1,但这不起作用。这些扩展方法不存在。

我是否错过了某些内容,或者为什么这些方法出现在文档中时在 .Net 5 中不可用?

如果我无法让它工作,是否有其他方法可以替代使用 GetEndpoint() 扩展方法?

我的所有目标是:我想在以下代码段中使用AuthenticationHandler

        var endpoint = Context.GetEndpoint();
        if (endpoint?.Metadata?.GetMetadata<IAllowAnonymous>() != null)
            return AuthenticateResult.NoResult();
Run Code Online (Sandbox Code Playgroud)

编辑:

事实证明,我缺少 .csproj 文件中的框架参考

<FrameworkReference Include="Microsoft.AspNetCore.App" />) 
Run Code Online (Sandbox Code Playgroud)

如此处所述。

但是,我不太了解它为我的项目提供了什么,以便彻底回答我的问题:为什么此扩展方法不能通过正常的 NuGet 包使用?

c# missing-features endpoint .net-core asp.net-core

7
推荐指数
1
解决办法
5120
查看次数

标签 统计

.net-core ×1

asp.net-core ×1

c# ×1

endpoint ×1

missing-features ×1