I have been trying to use the extension method GetEndpoint() as detailed here:
My project was initially targeting netstandard2.1
but then I read in the following post that this feature is for projects which target netcoreapp3.1
.
Can't access httpcontext extension methods in .net standard
I do not want to target .Net Core 3.1 because the Entity Framework Core side of my project uses features which were delivered in the latest release, targeting .Net Standard 2.1.
So I tried targeting .Net 5 to see if it would appear, which it hasn't. I've also tried installing the package Microsoft.AspNetCore.Http.Abstractions
but to no avail (and noted that this package targets netstandard2.0
). I even tried changing the target framework down to netcoreapp3.1
and that didn't work. These extension methods are just not there.
Have I missed something or why are these methods not available in .Net 5 when they appear in the documentation?
Is there an alternative to using the GetEndpoint() extension method, if I can't get it to work?
My aim in all of this: I would like to use the following snippet in an AuthenticationHandler
:
var endpoint = Context.GetEndpoint();
if (endpoint?.Metadata?.GetMetadata<IAllowAnonymous>() != null)
return AuthenticateResult.NoResult();
Edit:
It turns out that I was missing the Framework Reference from the .csproj file
<FrameworkReference Include="Microsoft.AspNetCore.App" />)
as described here.
However, I don't understand well enough what that delivers to my project in order to answer my question thoroughly as to why this extension method is not available through the normal NuGet packages?