You can read the ref and take a look in the Difference between ApiController and Controller in ASP.NET MVC, since people are commonly confused with them.
Questions tagged [asp.net-apicontroller]
456 questions
2
votes
2 answers
ContentResult of Web Api controller in Unit Test always returning null
The ContentResult I am trying to check in unit test of the getMethod(string id) is always returning null. The Service called by controller returns DTO Model.
I have tried
actionresult as OkNegotiatedContentResult
actionresult as…

ps_dev
- 69
- 1
- 9
2
votes
0 answers
.Net Core 2.1.6 Api Hangs when returning a statuscode 205
I have an Api that we need to return a status code 205 from. Whenever this code is hit, the Api just hangs, no response gets returned to PostMan, or to any tests. Even after disabling all middleware and custom libraries, it still behaves in the same…

Dirk
- 884
- 1
- 7
- 18
2
votes
1 answer
System.Web.Http.HttpResponseException in catch block while exception handling
I am intentionally making a violation of a unique constraint in my database, and trying to handle an exception.
This among else is in my form:
HttpResponseMessage response = KorisniciService.PostResponse(k);
if…

Faski
- 31
- 1
- 7
2
votes
1 answer
Setting Parameters before api Controller initializes
I'm trying to pass a parameter for database connection purposes in my apiController constructor.
for example by default in my baseAPIController i neeed the code to be '1'. But in this specific controller I need to change that parameter to '7'.
The…

Ana
- 41
- 1
- 7
2
votes
0 answers
c# apicontroller gets called twice when it is called only once by getasync
Hello I have encountered very interesting bug, and can't understand why is this happening. I call GetAllDocuments() method to api from my other project via GetAsync method of httpclient. But the problem is GetAllDocuments returns and then it gets…

Ben Sin
- 41
- 6
2
votes
1 answer
ASP.NET Core 2 WEB API - Dependency Injection
When using WEB API (only) is there a difference between API controller and normal Web Controller? I mean when adding a service like this using one of the lifetime:
services.AddSingleton

user2818430
- 5,853
- 21
- 82
- 148
2
votes
4 answers
Unit Test - How to set controller user to Generic Principal object
Updated full solution:
WebApi Controller method which I'm going to test :
using Microsoft.AspNet.Identity;
using System.Web.Http;
[Authorize]
public class GigsController : ApiController
{
private readonly IUnitOfWork _unitOfWork;
public…

Arjuna
- 33
- 1
- 11
2
votes
2 answers
Access Client certificate in ApiController hosted in Azure Worker Role
This could be a repeat question but I still could not find any answer that could resolve my issue so posting it again.
I have an azure worker role and I have added an ApiController to it using Owin selfhost(see this for reference).
In my custom…

ashish1238
- 53
- 6
2
votes
0 answers
How to provide a Service object to OWIN and access from Api controller
I have a self-hosted OWIN App and I want to provide a Service (MyService) object when the WebApp is started and the use it from the Api Controllers.
The Service object is instantiated just before I start up the OWIN app and I need to have access to…

Agustin Berbegall
- 75
- 1
- 7
2
votes
3 answers
.net api : trailing zeroes are truncated
I need the trailing zeroes to stay but when the 43.00 was deserialized in the api it just became 43.
Request payload in Chrome browser:
value in api controller:

John Dow
- 177
- 3
- 14
2
votes
0 answers
ModelState validation error duplication in asp.net mvc
I use asp.net mvc5, api conrollers.
I'm try valid data
[Required]
[RegularExpression(@"\+?[0-9]{7,15}", ErrorMessage = "Invalid Phone Number")]
public string PhoneNumber { get; set; }
And it work nice , but if I try send invalid…

Vova Leskiv
- 31
- 4
2
votes
3 answers
Why ASP.NET MVC app doesn't recognize user role changes right after modification?
I have an ASP.NET MVC hybrid app which has an ApiController besides the MVC Controllers. I'm using role based authorization attributes within both the MVC Controllers and the ApiController both at the controller level and sometimes on method level.…

Csaba Toth
- 10,021
- 5
- 75
- 121
2
votes
2 answers
API Controller Post method return type/value
I want to use a .NET Web API 2 Controller for my vb.net game.
I added one to my project and I updated my Global.axax.vb & Application_Start method per the instructions.
Right now I'm just trying to figure out how it works.
But I don't know what to…

SkyeBoniwell
- 6,345
- 12
- 81
- 185
2
votes
2 answers
Web API Routing Not Recognising Parameters
I have the following WebAPI controller:
namespace MyApp.WebApi.Controllers
{
[RoutePrefix("api/listing")]
public class ListingController : ApiController
{
[Route("{firstparam:int?}/{nextparam:int?}")]
public…

Paul Michaels
- 16,185
- 43
- 146
- 269
2
votes
1 answer
.ToList on IQueryable causes NullReferenceException when executed in background
My code works fine when executed synchronously, but fails when triggered via QueueBackgroundWorkItem.
UPDATE: the issue seems to be with the Sitefinity dynamic module manager I am using requiring HTTP context within the thread created by…

jmotes
- 2,669
- 2
- 22
- 19