All Questions
Tagged with .net-core asp.net-web-api
580
questions
84
votes
8
answers
89k
views
Remotely connect to .net core self hosted web api
I have a simple .net core web api with one action:
[Route("[action]")]
public class APIController : Controller
{
// GET api/values
[HttpGet]
public string Ping()
{
return ...
82
votes
10
answers
118k
views
How to set start page in dotnet core web api?
I try to build a web application with dotnet core web api,but i do not know how to set index.html as start page which can be done with dotnet framework web api easily. And i tried to use app....
81
votes
4
answers
75k
views
Is ApiController deprecated in .NET Core
Is it true that "ApiController will get deprecated in .NET Core"? Asking since I'm planning to use it in new projects.
46
votes
5
answers
24k
views
Type argument 'System.Net.Http.Headers.MediaTypeHeaderValue' violates the constraint of type parameter 'T'
I have a Web API solution (targeting .NET 4.6) with a couple of fairly lightweight .NET Core projects in it. I've packaged the .NET Core projects up as a NuGet package and installed them to the Web ...
32
votes
6
answers
50k
views
How to auto log every request in .NET Core WebAPI?
I'd like to have every request logged automatically. In previous .Net Framwork WebAPI project, I used to register a delegateHandler to do so.
WebApiConfig.cs
public static void Register(...
25
votes
4
answers
38k
views
ASP Core WebApi Test File Upload using Postman
I have created an endpoint that takes an arbitrary file:
[HttpPost()]
public async Task<IActionResult> CreateFile(IFormFile file)
When I test it with Postman, the file is always null.
Here is ...
22
votes
1
answer
30k
views
How to map config in IConfigurationSection to a simple class
Using MVC .net Core and building a concrete config class within the startup class. My appsettings.json looks like this:
{
"myconfig": {
"other2": "tester,
"other": "tester",
"root": {
...
20
votes
3
answers
32k
views
EF Core and big traffic leads to max pool size was reached error
We're using ASP.NET Entity Framework Core for querying our MSSQL database in our Web API app. Sometimes when we have big traffic, querying to DB ends with this error:
Timeout expired. The timeout ...
16
votes
1
answer
19k
views
How to store the token received in AcquireTokenAsync with Active Directory
Problem Statement
I am using .NET Core, and I'm trying to make a web application talk to a web API. Both require authentication using the [Authorize] attribute on all of their classes. In order to be ...
16
votes
3
answers
16k
views
How can I stub/mock services in ASP.NET Core tests
I'd like to test some classes that are part of ASP.NET Web Api project. I don't need request-response integration tests via TestServer (though they're nice) but I want to keep my tests as close to "...
14
votes
3
answers
22k
views
.Net Core 2.2 Web API getting 415 Unsupported Media type on a GET?
I have upgraded my WebApi project to .net core 2.2 and since then, all of my controllers are pulling 415 Unsupported Media type from every single GET call. Which is super strange because 415 is ...
12
votes
3
answers
16k
views
How to limit memory size for .net core application in pod of kubernetes?
I have a kubernetes cluster with 16Gb RAM on each node
And a typical dotnet core webapi application
I tried to configure limits like here:
apiVersion: v1
kind: LimitRange
metadata:
name: mem-...
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 ...
11
votes
2
answers
8k
views
How to add CosmosDB to .Net 6 WebAPI?
I want to use a CosmosDB SQL-API in a .Net 6 WebAPI. Is there also an AddCosmos() method available to inject client in different services or is it really necessary to implement my own cosmos-service ...
11
votes
1
answer
10k
views
.NET Core Microservice using RabbitMQ [closed]
I am planing to use Microservice architecture for a project. The selected technology stack is .NET Core with Docker and RabbitMQ as a simple service bus and this should be able to deploy on Linux.
...
10
votes
3
answers
13k
views
How to get IOptions in ConfigureServices method or pass IOptions into extension method?
I'm developing asp .net core web api 2.1 app.
I add JWT authentication service as an extension method in static class:
public static class AuthenticationMiddleware
{
public static ...
10
votes
4
answers
8k
views
.NET Core WebAPI dependency injection resolve null
I use .NET Core WebAPI with dependency injection and multiple authentication schemas (http basic, access keys, JWT). I inject some business services which require some authenticated user data. If user ...
10
votes
1
answer
5k
views
HttpClient PostAsJsonAsync behaving different in .NET Core and Classic .NET
I am hosting a Classic .NET WebAPI endpoint in IIS that accepts POST requests to upload a document.
I have created two console applications that will connect to the WebAPI and upload a document: One ...
9
votes
1
answer
18k
views
IActionResult vs ObjectResult vs JsonResult in ASP.NET Core API
What's the best option to use in a Web API that will return both HTTP status codes and JSON results?
I've always used IActionResult but it was always a Web App with a Web API. This time it's only Web ...
9
votes
4
answers
13k
views
Save Changes of IConfigurationRoot sections to its *.json file in .net Core 2.2
i was digging to find out the solution but didn't manage to find it, i bet that someone has encountered this problem, so what is the problem?.
For test i have created simple console application (...
9
votes
2
answers
8k
views
The command "dotnet bundle" exited with code 1 - VS 2017 Publish ASP.NET Core Web API
I'm getting the following error when trying to publish my Web API to a server:
The command "dotnet bundle" exited with code 1
This is the publish screen:
This is the error from output:
Can anyone ...
9
votes
1
answer
13k
views
MultipartFormDataStreamProvider for ASP.NET Core 2
I am in the process of migrating a project from ASP.NET MVC 5 to ASP.NET Core 2 and have run into some issues regarding the MultipartFormDataStreamProvider
As far as I can tell it's not yet a part of ...
8
votes
1
answer
29k
views
JWT Token Expiration time failing .net core [duplicate]
I am trying to implement Token Based Authentication through refresh tokens and JWT in .NET Core 2.1.
This is how I am implementing the JWT Token:
Startup.cs
services.AddAuthentication(option =>
...
8
votes
2
answers
3k
views
AspNetCore.Mvc.Core Version Mismatch
I'm attempting to write a unit test for a Controller extension method, but during the Test project's build process I receive the following error message.
MyControllerExtensionsTests.cs(17, 26): [...
8
votes
1
answer
13k
views
ASP.Net Core Access to the Path is Denied with IFormFile
Just writing a simple ASP.NET Core WebAPI and when using a simple POST endpoint accepting IFormFiles:
[HttpPost]
public async Task<List<string>> Post(List<IFormFile> ...
8
votes
1
answer
5k
views
EF Core: Get Authenticated username in Shadow Properties
As a part of logging who entered/updated the data I am adding 4 common fields (Created By, Created Date, Modified By, Modified Date) in all entities. For this, I am using shadow properties feature ...
8
votes
4
answers
4k
views
.Net Core WebApi refuses connection in Docker container
I am trying out Docker with a small WebApi which I have written in dotnet core.
The Api seems to work fine because when I run it with dotnet run it starts normally and is reachable on port 5000. But ...
8
votes
3
answers
4k
views
Authorization with Asp.Net Core WebAPI
Admittedly, this is a first stab at building an Asp.Net Core web api project.. One requirement is to support OAuth2. The Api and Identity server are two separate projects, both started from an Asp....
8
votes
3
answers
6k
views
How to set dynamic entity to dbcontext Entity Framework Core?
I got a method that receives an entity like string to return a list of that entity.
What I want is set the entity dynamically and return the result.
What I need is something like this:
DbContext.Set &...
7
votes
4
answers
5k
views
Azure App service can't start because it can't find swagger documentation xml using ASP.NET Core
Update 2: The file does not get published. That is what is wrong. However, I can't figure out why one of my computers can publish it the right way and the other doesn't after the Visual studio upgrade....
7
votes
4
answers
14k
views
How to add Basic authorization header in the Swagger in ASP .Net core
How to add basic authorization header in Swagger in Asp .Net core. By default the api key treats as a query string but I need to customize that so that it will include in the header.
7
votes
1
answer
7k
views
Attribute Based Routing VS Convention Based Routing - Best Practice for ASP.net Core RESTful APIs [closed]
I'm an experienced .NET developer, making my first steps in .NET Core in the passed few days, more specific in building RESTful APIs using ASP.net Core.
I know there are 2 possible routing options - ...
7
votes
2
answers
15k
views
Calling asmx service from .net core api2
i need to call an old asmx web service (I have not control over)from a .net core web api
is it possible?
thanks
7
votes
1
answer
2k
views
Adding role claims - should i use the IClaimsTransformer
We would like to add a lot of role claims to the current principal (we use the Authorize(Roles) attribute), and found the IClaimsTransformer that looks like a perfect fit.
We've registerd it like ...
7
votes
1
answer
9k
views
Cant get ASP.NET Core Web API to work with IIS [closed]
I'm building an ASP.NET Core MVC Web Api application and I'm trying to get it to work with IIS on my own machine. I have read different blogs and tried different things but just can't seem to get it ...
7
votes
1
answer
739
views
What OAuth flow to use for IONIC2 app and Identity Server4
I've been researching oauth 2 and IdentityServer4 for the past day and a half and can say that I think the preferred method to use in this scenario would be hybrid flow. It seems that in the past it ...
6
votes
1
answer
19k
views
How to download a ZipFile from a dotnet core webapi?
I am trying to download a zip file from a dotnet core web api action, but I can't make it work. I tried calling the action via POSTMAN and my Aurelia Http Fetch Client.
I am able to create the ...
6
votes
1
answer
8k
views
IActionResult or async Task<IActionResult> what are the advantages?
We're going to create a new API in dotnet core 2.1, this Web API will be a high traffic/transactions like 10,000 per minute or higher. I usually create my API like below.
[HttpGet("some")]
public ...
6
votes
2
answers
18k
views
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. 3
I am trying to make a .NET Core Web API but I couldn't find out a solution for my problem.
Full error is
[ERR] An exception occurred in the database while iterating the results of a query for context ...
6
votes
3
answers
14k
views
Dotnet Core 3.1: How to use AddJsonFile with absolute path to file?
I have a dotnet app in which I need to pull in configuration from both relative paths (the regular appsettings.Json, appsettings.Development.json), and also, from the absolute path /config/appsettings....
6
votes
1
answer
2k
views
How use JWT Bearer Scheme when working with WebApplicationFactory
I have a working web API that I recently updated to use JWT auth and, while it is working when I run it normally, I can't seem to get my integration tests to work.
I wanted to start working on ...
6
votes
3
answers
17k
views
Null reference exception being thrown in EF LINQ query if-clause
I couldn't find the exact words to explain what's happening, so if this is a duplicated question, I apologize.
I tried to do a quite simple AND condition if-clause inside a LINQ Query, in order to ...
6
votes
3
answers
5k
views
Publish profile with MSBuild 2022 not working
MsBuild.exe MyProject.csproj /p:Configuration=Release /p:DebugType=None /p:Optimize=True /p:DeployOnBuild=true /p:PublishProfile=MyPublishProfile /p:VisualStudioVersion=16.0"
We used to run above ...
6
votes
0
answers
774
views
WEB API in .NET Core 2.0.6 is slower than .NET 4.5.2?
I've made a simple test to compare performance of ASP.NET WEB API with .Net Framewrok 4.5.2 and with dotNet Core 2.0.6
Just runned locally, on my PC.
I've created a new project with framework 4.5.2, ...
6
votes
0
answers
1k
views
Can't access encoded form data from context.Request.Form
I'm building some custom middleware into my request pipeline which will generate JWT bearer token if the posted form data is valid (hooked into AspNetCore.Identity).
Based on Nate Barbettini's great ...
5
votes
2
answers
1k
views
.Net Framework dll not working on .Net Standard project
I have referenced the .Net framework ddl to .Net standard 2.0. It will show me below errors.
System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
The ...
5
votes
5
answers
12k
views
Postman send both data in json and image
I have created one API and it is adding data in database, with values and image.
In postman I am calling that and setting image in form-data and other values in raw in JSON but still in image I am ...
5
votes
2
answers
8k
views
download PDF file using angular 2 and .Net core webapi
I am trying to download PDF (and later word,excel and image) file using angular 2 with .Net core web api. I have pasted some code sample here which downloads the file but when I try to open the ...
5
votes
3
answers
37k
views
No authenticationScheme was specified error even when JWT Authentication Specified
I'm new to AzureAD authentication. I setup my Web API with below settings in startup.cs
services.AddAuthentication(sharedopt => sharedopt.DefaultScheme = JwtBearerDefaults....
5
votes
3
answers
7k
views
Post Action with model class vs DTO
This MSDN link explains why it is a good practice to use DTOs classes for web API. This is understandable, what confuses me is in the same page, the post method uses the model class instead of the ...