无法访问.net标准中的httpcontext扩展方法 [英] Can't access httpcontext extension methods in .net standard

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

问题描述

我有一个.NET标准库,我想在其中编写.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>

(您可以在您还需要:

  1. 使用 Microsoft.NET.Sdk.Web MSBuild SDK:
  1. use the Microsoft.NET.Sdk.Web MSBuild SDK:
<Project Sdk="Microsoft.NET.Sdk.Web">

  • 或添加框架参考:

  • or add the framework reference:

    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    

  • 参考: 查看全文

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