Questions tagged [asp.net-apicontroller]

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.

391 questions
29
votes
5 answers

How to return JSON in an ApiController for a single method?

Currently, my ApiControllers are returning XML as a response, but for a single method, I want to return JSON. i.e. I can't make a global change to force responses as JSON. public class CarController : ApiController { …
23
votes
2 answers

ApiController vs ODataController when exposing DTOs

Can someone explain me when I should inherit my controller form ODataController vs ApiController ? The question is caused by the fact that results returned by ApiController can be filtered with OData query. If I apply QueraybleAttribute to…
Pavel Voronin
  • 11,811
  • 6
  • 54
  • 113
22
votes
1 answer

Circular references preventing serialization of object graph

I've got a simple data model involving Weeds and Weed Families. WeedFamily <-1---*-> Weed (WeedFamily and Weed have a one-to-many relationship) I'm attempting to complete my first ApiController so that I can easily retrieve my data as JSON for an…
Jonathan Wilson
  • 3,715
  • 1
  • 21
  • 36
20
votes
3 answers

Need to add custom header to request in unit test

I finally was able to get the HttpContext.Current to be not null by finding some code online. But I still have not be able to add custom headers to the request in my unit test. Here is my test: [TestClass] public class TagControllerTest { …
18
votes
3 answers

Why is anonymous user trying to access /admin/host/synctriggers?

Since a few days ago, I have started receiving error messages from all my Azure websites: "The controller for path '/admin/host/synctriggers' was not found or does not implement IController." This is coming my an anonymous user (or bot). The full…
Windhoek
  • 965
  • 8
  • 23
15
votes
0 answers

IdentityServer3 - rejected because invalid CORS path

We have an ASP.NET MVC application that is authenticating without issue against IdentityServer3, however the web API part of the application using ApiController's start to fail if the user waits before proceeding with AJAX functionality after about…
Gavin
  • 5,068
  • 6
  • 37
  • 80
12
votes
3 answers

Passing JSON Array from Javascript to Web API Controller method

I was not able to get the JSON array parameters in web api controller method (SaveDetails). Here are my code. JavaScript Code: $.ajax( { url : "api/Test/SaveDetails", type : "POST", data : { …
Saravana Kumar
  • 3,457
  • 4
  • 12
  • 30
12
votes
4 answers

An error occurred when trying to create a controller of type 'TypeNewsController'

I have searched long and hard but found nothing that helped yet. Where am I going wrong? I really do not know what to do. I wrote all the details below. I've tried and did not succeed. An error occurred when trying to create a controller of type …
10
votes
1 answer

TableController vs ApiController in Azure Mobile Apps

I'm just getting started with Mobile Apps. I'm used to making APIs with ApiController of Web API. The default project template for Mobile Apps in VS2015 comes with a sample TodoItemController that inherits from TableController. It looks like there…
Mark13426
  • 2,429
  • 4
  • 35
  • 72
8
votes
4 answers

Conventional Routing in ASP.NET Core API

Problem: I'm creating an API Application with NET Core 3.1. I'd like to avoid to set route attribute over every ApiControllers and Actions. I tryed a lot of combinations over UseEndpoints to set a conventional route, but i'm failing. With some…
7
votes
1 answer

How to get the authentication header from a request sent to an ASP.NET core 2.0 API controller action

I am working on an ASP.NET Core 2.0 RESTful API. I have a scenario where I need to use an HTTPGet method to call an action on my API controller and I need to extract a username and password value that will be used to call another 3rd party API. The…
7
votes
3 answers

Custom ApiExplorer with Namespace based ApiControllers

I'm trying to add API documentation at my backend system. Default ApiExplorer and Help page worked absolutely great until the moment I introduced versions to my Api Controllers. In order to add versions I created sub folders under the Controllers…
6
votes
0 answers

Azure Web Api - Waiting Sql Connection every 4 minutes and 30 minutes

Within a request on an ApiController, I'm tracking the duration of awaiting the Sql Connection to open. await t.TrackDependencyAsync(async() => { await sqlConnection.OpenAsync(); return true; }, "WaitingSqlConnection"); If my request is not called…
6
votes
1 answer

Integration test causes Entity Framework to time out

I'm currently writing integration tests using nunit for a previously untested server that was written in C# using ApiController and Entity Framework. Most of the tests run just fine, but I've ran into two that always cause the database to time out.…
5
votes
5 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
  • 11
1
2 3
26 27