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
6
votes
1 answer
Web API Controller Method -- Request is null
When calling the method shown below, Request is always null. I have some simple methods returning JSON data from controllers in an MVC4 app with controllers using ApiController as a base class. The code for my directory function is as…

Thomas McNamee
- 692
- 1
- 6
- 14
5
votes
6 answers
Is there a way to get Current User in Api Controller
i am using asp.net Authorization to log in with Angular js for client side ,i need to get Current user logged in
i need to get current User to save any operation in my logger Table,
and httpcontext.session.current is null ,
is there is another way…

Ȝlaa A. Saleh
- 87
- 1
- 1
- 11
5
votes
1 answer
How to send byte array in c# ApiController
Could someone please tell me how i can test this function :
[RoutePrefix("service")]
public class TestControler : ApiController
{
[Route("function-route")]
[HttpPost]
public HttpResponseMessage Testfunction(TestData t_testData )
{
…

user1911091
- 1,219
- 2
- 14
- 32
5
votes
1 answer
C# Web Api - IValidatableObject validationContext service provider is null
I am trying to use IValidatableObject validation in a web api 2 context. The Validate method is getting called, but the ValidationContext parameter passed has a method called GetService which always returns null because the service provider of the…

Samuel Poirier
- 1,240
- 2
- 15
- 30
5
votes
1 answer
How to download binary file using ASP.net Web API and Javascript?
I have a Web API controller that looks like this:
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;
using System.Threading.Tasks;
using System.IO;
namespace APIIntegration.Controllers
…

Vivian River
- 31,198
- 62
- 198
- 313
5
votes
1 answer
ASP.NET MVC 4 ApiController and Normal Controller Routes
I have a project that is used solely for API requests into our app and we are using an ASP.NET MVC 4 project. We have some Controllers that derive from the ApiController and others that derive from the normal Controller class. The issue is that I…

Nick Olsen
- 6,299
- 11
- 53
- 75
4
votes
2 answers
API Json response to C# Object with capital case properties first letter
I've made an API where after an Entity Framework elaboration I send an object serialized in Json.
My Object:
public class Package
{
public int Items { get; set; }
public string Code { get; set; }
public string Description { get; set; }
…

Alessandro Albi
- 121
- 1
- 3
- 13
4
votes
2 answers
Why does ApiController return empty Dictionary when the value type is nullable?
Consider this controller:
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
namespace WebApplication.Controllers
{
[ApiController]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
…

Hans Kurel
- 41
- 2
4
votes
1 answer
How do I add an WebApiConfig to my UmbracoApiController?
I'm trying to create a APIcontroller for my Umbraco V8 package. The API is working fine but I only want my backoffice AngularControllers to have access to the API. I wish to create a attribute like described in this answer…

Bart
- 75
- 6
4
votes
1 answer
Swagger works only with an apicontroller, not with an mvc controller?
I am using swagger for my api documentation but it seems that swagger only detact
only those class that inherit ApiController not those classes those inherit
basecontroller Am i right? Or there is some way to make swagger work with mvc…

Nur
- 41
- 3
4
votes
0 answers
Error when DeserializeObject which consist DateTime in newtonsoft.js
I am trying to deserialize an object in web api controller. It consist of DateTime. The format of date Time property is "dd-MM-YYYY". I have set format of json serialzer dd-MM-YYYY in global.asax file. Still it gives me error "could not convert…

Safi Mustafa
- 515
- 7
- 22
4
votes
3 answers
What's the best way to communicate between angularjs and mvc5?
I've some confusions to transfer data between angularjs and MVC5. I am creating single page application (SPA).
What is the best way to work with angularjs? Is MVC controllers or MVC APIs ?.
I read it here that api's are good for SPA. So, do I need…

Sarbanjeet
- 253
- 1
- 15
4
votes
0 answers
Owin, WebApi, and UseCookieAuthentication
I've configured OWIN in my ASP.NET MVC application using cookie authentication, but when I attempt to access an ApiController with an Authorize attribute on it, authorization fails and I can't figure out why. Stepping into the IsAuthorized method of…

Anthony Compton
- 5,271
- 3
- 29
- 38
4
votes
1 answer
APIController "Executed" method?
In an ApiController action I need to close a connection to a database as soon as the action is finished executing.
Under a controller I override OnActionExecuted to accomplish this.
How would I accomplish this under an ApiController action?
Thanks

Leo
- 900
- 1
- 11
- 26
3
votes
1 answer
Injecting DbContext to API controllers makes them return index.html instead of the actual result on published version of NET5 React webapp
I am using a default ReactApp project from visual studio with net5 as framework. This by default comes with a WeatherApiController. Now the problem is, I created a DataContext (DbContext) which I am trying to inject in the…

Robert Balassan
- 31
- 4