All Questions

Filter by
Sorted by
Tagged with
229 votes
6 answers
347k views

Return file in ASP.Net Core Web API

Problem I want to return a file in my ASP.Net Web API Controller, but all my approaches return the HttpResponseMessage as JSON. Code so far public async Task<HttpResponseMessage> ...
Jan Kruse's user avatar
  • 2,675
113 votes
16 answers
198k views

The configuration file 'appsettings.json' was not found and is not optional

The Azure error is: .Net Core: Application startup exception: System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. So this is a bit ...
Frank's user avatar
  • 1,341
102 votes
6 answers
90k views

Unit testing controller methods which return IActionResult

I'm in the process of building an ASP.NET Core WebAPI and I'm attempting to write unit tests for the controllers. Most examples I've found are from the older WebAPI/WebAPI2 platforms and don't seem ...
Jake Shakesworth's user avatar
70 votes
13 answers
72k views

Enable OPTIONS header for CORS on .NET Core Web API

I solved this problem after not finding the solution on Stackoverflow, so I am sharing my problem here and the solution in an answer. After enabling a cross domain policy in my .NET Core Web Api ...
Niels Brinch's user avatar
  • 3,273
67 votes
7 answers
160k views

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....
Magnus Wallström's user avatar
57 votes
5 answers
137k views

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 ...
amiry jd's user avatar
  • 27.3k
50 votes
17 answers
77k views

ASP.NET CORE, Web API: No route matches the supplied values

PLEASE NOTE: This question was asked in 2016. The original answer to this problem was to update the microsoft api versiong package. In the current days, the problem reoccurs, but for other reasons. ...
Benjamin Schäublin's user avatar
50 votes
4 answers
60k views

Correct way to return HttpResponseMessage as IActionResult in .Net Core 2.2

In .Net Core 2.2. I am creating a API Controller that routes the request to another Http endpoint based on payload. [Route("api/v1")] public class RoutesController : Controller { ...
LP13's user avatar
  • 32.3k
44 votes
2 answers
82k views

.NET Core RuntimeIdentifier vs TargetFramework

Can someone explain the purpose of these two in the csproj file (VS2017): <TargetFramework>netstandard1.6</TargetFramework> <RuntimeIdentifier>win7</RuntimeIdentifier> I just ...
Alezis's user avatar
  • 2,719
39 votes
1 answer
42k views

Using Dependency Injection with .NET Core Class Library (.NET Standard)

I have gone through the link: https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/dependency-injection and learnt that how I can use dependency injection for Web API. As mentioned in ...
Banketeshvar Narayan's user avatar
38 votes
4 answers
23k views

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 ...
Jason Yandell's user avatar
31 votes
3 answers
79k views

Routes in ASP.net Core API

I read lot of topic about routes for API in Asp.net core but I cannot make it work. First, this is my controller : Public class BXLogsController : Controller { //[HttpGet("api/[controller]/ID/{...
Gobelet's user avatar
  • 473
29 votes
11 answers
29k views

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 ...
Nishan's user avatar
  • 4,092
29 votes
3 answers
15k views

Localization in external class libraries in ASP.NET Core

I have two projects: MyWebApp - ASP.NET Core Web API MyServices - .NET Core class library, which contains helpful services for project above How can I add localization with IStringLocalizer to ...
Yurii N.'s user avatar
  • 5,563
28 votes
2 answers
44k views

Using ApiControllerAttribute without using RouteAttribute

In ASP.NET Core (v 2.1.5) you can create controllers without having them inherit from Controller class (as you know). And if you do, you have to use RouteAttribute to define your routes. But, I'm ...
amiry jd's user avatar
  • 27.3k
26 votes
1 answer
16k views

How does reloadOnChange of Microsoft.Extensions.Configuration work for appsettings.json

In two projects (a .NET Core Web API and a .NET Core WindowsService) I am using appsettings.json for the configuration. var configuration = new ConfigurationBuilder() .SetBasePath(System.IO....
monty's user avatar
  • 8,265
24 votes
2 answers
60k views

Bearer error="invalid_token", error_description="The signature is invalid"

I have a angular application that request a token from azure. The login went well and I get a token. This token is now send from the angular app to a net core webapi application. Net core should ...
Thom Kiesewetter's user avatar
23 votes
2 answers
15k views

WebAPI Core routing issues

So, I am playing around with Web API (ASP.NET Core 2) and having routing issues. I have several controllers such as: SchoolController TeacherController. Both have Gets: Get(int id) Problem is that ...
Ahmed ilyas's user avatar
  • 5,772
23 votes
2 answers
15k views

Keep ASP.NET core app running all the time in IIS

I am hosting an ASP.NET Core (2.2) app in IIS. The app is using a custom app pool with below settings: .NET CLR version: No Managed Code Start Mode: Always Running Idle Time-out (minutes): 0 My ...
Brij's user avatar
  • 12.3k
22 votes
3 answers
41k views

How to do model validation in every method in ASP.NET Core Web API?

I am getting into ASP.NET Core 2.0 with Web API. One of my first methods are my login: /// <summary> /// API endpoint to login a user /// </summary> /// <param name="data">...
PassionateDeveloper's user avatar
21 votes
1 answer
25k views

Post Stream in ASP.NET Core Web Api

Hello lovely people of Stack Overflow. Since yesterday I have a problem and I have been browsing SO since then. I have a UWP Client and ASP.NET Core Web Api. I just want to send a stream to my web api ...
Hasan Hasanov's user avatar
21 votes
4 answers
18k views

SwaggerUI not display enum summary description, C# .net core?

I used https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-2.1&tabs=visual-studio#xml-comments to show my classes summaries description in ...
Mohammad Dayyan's user avatar
19 votes
3 answers
16k views

How to validate AWS Cognito JWT in .NET Core Web API using .AddJwtBearer()

I was having some trouble figuring out how to go about validating a JWT given to the client by AWS Cognito inside my .NET Core Web API. Not only could I not figure out what the variables for ...
foxtrotuniform6969's user avatar
19 votes
6 answers
36k views

Version Conflict detected for Microsoft.EntityFrameworkCore.Install

I am getting the following error when adding an asp.net core api to an existing project I am working on. "Version Conflict detected for Microsoft.EntityFrameworkCore.Install/reference Microsoft....
user1474992's user avatar
18 votes
1 answer
16k views

ASP.NET Core CreatedAtRoute No route matches the supplied values

Using ASP.NET Core 2.0.0 Web API, I'm trying to build a controller to do a database insert. The information can be inserted into the database just fine, but returning a CreatedAtRoute throws an '...
Mike's user avatar
  • 517
18 votes
2 answers
21k views

Reading appsettings.json from .net standard library

i have started a new RESTful project using .NET Core Framework. I divided my solution in two parts: Framework (set of .NET standard libraries) and Web (RESTful project). With Framework folder i ...
Lollo's user avatar
  • 595
16 votes
1 answer
16k views

Return type of a file for Swagger documentation with dotnet core

I'm using Swagger for dotnet core to document my dotnet core Web API. I've read the documentation telling me that I need to add [ProducesResponseType(typeof(XXXXX),200)] above the controller ...
chris31389's user avatar
  • 8,818
16 votes
3 answers
13k views

How can I add kid to jwt header using SecurityTokenDescriptor in .netcore

I am using .netcore 2 with JwtSecurityToken to generate a token var jwtSecurityToken = new JwtSecurityToken( issuer: issuer, audience:issuer, ...
flyingpig's user avatar
  • 602
15 votes
2 answers
17k views

.Net Core ValidateAntiForgeryToken throwing web api 400 error

Visual Studio 2017 with Web Api using .net Core 1.1 I'm using, but I am getting a 400 Bad Request Error. Error Occurs in every way: Angular http Fiddler Postman SoapUI Swagger ASP.NET Web API “...
user avatar
15 votes
3 answers
13k views

How to setup an auto watch run for .NET Core 3.1 projects using Visual Studio Code?

I need to setup an auto restart when some source code file modifies. I'm using VS Code with Dotnet Core 3.1 to develop a web api. When debug starts I can see my REST Api published in http://...
Erick V.'s user avatar
  • 151
13 votes
2 answers
4k views

Jwt Bearer and dependency injection

I am trying to configure my Jwt Bearer issuer key but, in production usually, I use Azure Key Vault wrapped by a KeyManager. The KeyManager class is configured in Dependency Injection but, in ...
Edoardo's user avatar
  • 375
13 votes
6 answers
26k views

Post Multiple Parameters Without DTO Class

I have an action on my web project which calls to an API [HttpPost] public async Task<IActionResult> ExpireSurvey(int id) { var token = await HttpContext.GetTokenAsync("...
egmfrs's user avatar
  • 1,327
13 votes
2 answers
14k views

Handling Model Binding Errors when using [FromBody] in .NET Core 2.1

I am trying to understand how I can intercept and handle model binding errors in .net core. I want to do this: // POST api/values [HttpPost] public void Post([FromBody] Thing value) ...
Wayne B's user avatar
  • 730
13 votes
5 answers
34k views

How to set AWS credentials with .net Core

I have to debug an existing project about .net Core and AWS. Our project runs well on our AWS instance but we can't run the project in local. Firstly we got the AmazonServiceException: Unable to find ...
Dorian Sanchez's user avatar
13 votes
4 answers
16k views

Why does the configuration of .NET Core options not work with a generic type parameter?

I have a .NET Core WebApi project. To read the appsettings in an easy way, I configure the options to be injected with DI. This works fine. However if I try to call Configure<>() with a generic ...
Emaro's user avatar
  • 1,447
12 votes
2 answers
8k views

.NET Core JWTBearer skip self-signed certificate validation for local communication with identity server

I have two API projects, one that's based on the .NET Framework 4.6.2 (an old API) and one that's based on .NET Core 2.0. The old API can disable self-signed certificate validation quite simply: ...
riqitang's user avatar
  • 3,301
12 votes
6 answers
28k views

passing an array to a asp net core web api action method HttpGet

I am trying to send an array of integers to my action method the code looks like so: [HttpGet] public async Task<IActionResult> ServicesByCategoryIds([FromQuery] int[] ids) { ...
zoran djipanov's user avatar
12 votes
2 answers
3k views

ASP.NET Core 5 returning JSON adding $id and $values properties

I'm using ASP.NET Core 5. As below, I'm using System.Text.Json: public IActionResult Index() { var result = GetAllMenuItems(); return Ok(result); } The expected shape of my JSON is: [ { ...
Uttam Ughareja's user avatar
12 votes
2 answers
18k views

Is services.AddSingleton<IConfiguration> really needed in .net core 2 API

I accessed appsettings.json In .NET Core 2 Web API Controller simply by adding below: public class MyController : Controller { private readonly IConfiguration appConfig; public ...
Jawad Al Shaikh's user avatar
12 votes
1 answer
7k views

add google authentication to **Existing** .net core 2 web api project

TL;DR - how to add authentication to an existing default core 2 web api project that was started without auth. Details - I've got an existing .net core 2 web api project with no authentication ...
JanivZ's user avatar
  • 2,335
12 votes
5 answers
10k views

Alternative to Server.Transfer in ASP.NET Core

I am migrating an ASP.NET application to ASP.NET Core and they have some calls to HttpServerUtility.Transfer(string path). However, HttpServerUtility does not exist in ASP.NET Core. Is there an ...
Connie Yau's user avatar
12 votes
1 answer
3k views

Dotnet core + (plus) sign in Web API routing

I work on web API project in the dotnet core and check user mobile number exists check. [Route("api/[controller]")] public class UserController : Controller { [HttpGet] [Route("mobile/exist/{...
Sender's user avatar
  • 6,760
12 votes
5 answers
7k views

How to remove WebDav in Startup.cs ASP.NET Core

I published a .NET Core Web API through FTP. By default, some of the methods weren't working(put and delete), because the server has WebDAV enabled as default. To remove this, after publishing the ...
BroDev's user avatar
  • 590
12 votes
3 answers
4k views

Visual Studio keeps adding IIS Express back into my launchsettings.json

I am trying to remove the IIS Express profile from my .NET Core launch settings but every time i repoen the solution, Visual Studio adds it back in again. For example, in a new project my launch ...
Kevin Brydon's user avatar
  • 12.9k
11 votes
4 answers
10k views

DataMember Attribute is not honored in dotnet core 3.0

I created a sample dotnet core 3.0 Web API project and did the following changes, Create a Model class TestData using System.Runtime.Serialization; namespace WebApplication17.Models { [...
Jitendra's user avatar
  • 762
11 votes
1 answer
12k views

Populating AspNetUserLogins and AspNetUserTokens

I've tried quite a few examples from the internet (e.g. first, second and others) and everything works fine except the fact that tables AspNetUserLogins and AspNetUserTokens don't show any data after ...
Alexandru Stefan's user avatar
11 votes
2 answers
41k views

How to add bearer token authentication to typed HttpClient in Asp.Net Core 6

I'm trying to setup a web api using ASP.Net Core 6 so that users can hit my end points and then I do some work in D365 behind the scenes using a privileged account. I'm using a typed HTTP Client, but ...
Michael Kubala's user avatar
11 votes
3 answers
23k views

asp.net core 2 Web API timeout issue

I have a .net core web api and one of the end point runs a stored procedure that takes 3-4 minutes to complete. API is deployed to IIS. When I make a httpGet , I get 502 Bad Gateway error. Looking ...
ProgSky's user avatar
  • 2,590
11 votes
2 answers
27k views

System.InvalidOperationException: Unable to resolve service for type [duplicate]

I'm working on a Web API with ASP.NET Core. When I'm executing my API with a post request, an exception is throwing before my break point in the Post method of UnitController. Exception Request ...
KJBTech's user avatar
  • 1,961
10 votes
2 answers
14k views

Logging Polly wait and retry policy ASP.NET CORE 2.1

I need to log retry policy defined via Polly in APS.NET CORE 2.1+. My code is below showing Polly retry polly and using HttpClient. public IServiceProvider ConfigureServices(IServiceCollection ...
Pingpong's user avatar
  • 7,859

1
2 3 4 5
30