Questions about ASP.NET Core web APIs and web apps that are not dependent on MVC Views or Razor Pages
Questions tagged [asp.net-core-webapi]
5650 questions
33
votes
3 answers
ASP.NET Core JWT mapping role claims to ClaimsIdentity
I want to protect ASP.NET Core Web API using JWT. Additionally, I would like to have an option of using roles from tokens payload directly in controller actions attributes.
Now, while I did find it out how to use it with…
![](../../users/profiles/2736919.webp)
dee zg
- 10,582
- 7
- 33
- 59
32
votes
1 answer
Mock HttpRequest in ASP.NET Core Controller
I'm building a Web API in ASP.NET Core, and I want to unit test the controllers.
I inject an interface for data access, that I can easily mock. But the controller has to check the headers in the Request for a token, and that Request doesn't seem to…
![](../../users/profiles/4364057.webp)
Squirrelkiller
- 1,557
- 1
- 15
- 29
31
votes
3 answers
Enum type no longer working in .Net core 3.0 FromBody request object
I have recently upgraded my web api from .Net core 2.2 to .Net core 3.0 and noticed that my requests are getting an error now when I pass an enum in a post to my endpoint. For example:
I have the following model for my api endpoint:
public…
![](../../users/profiles/2218458.webp)
Shawn
- 1,993
- 11
- 40
- 79
30
votes
8 answers
The input was not valid .Net Core Web API
I am facing a weird issue and almost spent 4 hours with no luck.
I have a simple Web API which I am calling on form submit.
API-
// POST: api/Tool
[HttpPost]
public void Post([FromBody] Object value)
{
…
![](../../users/profiles/5014099.webp)
Souvik Ghosh
- 3,824
- 10
- 45
- 64
30
votes
4 answers
How to compile .NET Core app for Linux on a Windows machine
I'm developing a .NET Core app on a Windows 10 machine (with Visual Studio 2015 update 3 + Microsoft .NET Core 1.0.1 VS 2015 Tooling Preview 2) which should published on an Ubuntu 16 machine. To do that, I have to move my source code to the end…
![](../../users/profiles/645167.webp)
amiry jd
- 18,602
- 10
- 58
- 127
29
votes
4 answers
How can I get my .NET Core 3 single file app to find the appsettings.json file?
How should a single-file .Net Core 3.0 Web API application be configured to look for the appsettings.json file that is in the same directory that the single-file application is built to?
After running
dotnet publish -r win-x64 -c Release…
![](../../users/profiles/272529.webp)
Jason Yandell
- 781
- 1
- 6
- 9
29
votes
6 answers
How to properly integrate OData with ASP.net Core
I'm trying to create a new ASP.NET Core project with a "simple" web api using OData and EntityFramework. I have previously used OData with older versions of ASP.NET.
I have set up a controller with only a simple get function. I've managed to get it…
![](../../users/profiles/955118.webp)
Sli
- 291
- 2
- 4
- 6
29
votes
1 answer
How to get content value in Xunit when result returned in IActionResult type
I have a unit test project using Xunit and the method we are testing returns IActionResult.
I saw some people suggest using "NegotiatedContentResult" to get the content of the IActionResult but that doesn't work in Xunit.
So I wonder how to get the…
![](../../users/profiles/6506156.webp)
Julie C.
- 449
- 2
- 6
- 17
28
votes
6 answers
How do I resolve the issue the request matched multiple endpoints in .Net Core Web Api
I notice that there are a bunch of similar questions out there about this topic.
I'm getting this error when calling any of the methods below.
Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints.…
![](../../users/profiles/799520.webp)
Magnus Wallström
- 1,029
- 4
- 12
- 23
28
votes
10 answers
The application completed without reading the entire request body, .net core 2.1.1
I have created a user register controller to register users with repository design pattern. My controller looks like this.
[Route("api/[controller]")]
public class AuthController : Controller
{
private readonly IAuthRepository…
![](../../users/profiles/5260872.webp)
Nishān Wickramarathna
- 1,964
- 1
- 18
- 28
28
votes
2 answers
.NET Core RuntimeIdentifier vs TargetFramework
Can someone explain the purpose of this two in csproj file (VS2017):
netstandard1.6
win7
I just migrated from VS2015 and now can't publish my web api because it looks I…
![](../../users/profiles/665550.webp)
Alezis
- 2,309
- 2
- 21
- 30
28
votes
1 answer
Registering a new DelegatingHandler in ASP.NET Core Web API
I want to create a new Handler that extends DelegatingHandler to enable me to do stuff before getting as far as the controller. I have read in various places that I need need to inherit from DelegatingHandler then overrride SendAsync() like…
![](../../users/profiles/723645.webp)
Ben
- 4,915
- 7
- 40
- 57
27
votes
2 answers
Get service from WebApplicationFactory in ASP.NET Core integration tests
I want to set up my tests using WebApplicationFactory as detailed in
Integration tests in ASP.NET Core.
Before some of my tests I need to use a service configured in the real Startup class to set things up.
The problem I have is that I can't see…
![](../../users/profiles/1128318.webp)
Simon Vane
- 1,686
- 2
- 17
- 21
27
votes
6 answers
.NET Core UseCors() does not add headers
This would be a duplicate of How does Access-Control-Allow-Origin header work?, but the method there also isn't working for me. I'm hoping I'm just missing something.
I am trying to get a Access-Control-Allow-Origin header in my response from my…
![](../../users/profiles/1940394.webp)
David
- 4,249
- 5
- 27
- 56
26
votes
6 answers
How to add method description in Swagger UI in WebAPI Application
I am using Swagger as my API tooling framework and it is working out great so far. I just came across this page https://petstore.swagger.io/
and saw how each method has a description. For example,
POST: pet/ is described by add a new Pet to the…
![](../../users/profiles/280772.webp)
Lost
- 8,195
- 27
- 95
- 163