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.

456 questions
3
votes
1 answer

404 not found when trying to run Api Controller function from ASP.NET core 5 web app

I am trying to create an API controller in my ASP.NET core 5 Razor Pages web application. I have created the Api Controller inside a folder named Api in Visual studio. Then when I try to run the following url to test that the api controller works, I…
3
votes
1 answer

Add/Skip ApiController for Web API in .Net Core

I have created windows forms application in .netcore 3.1 , that host two WEB Api services, using WebHostBuilder from the framework dependence of AspNetCore 3.1. (one on port 5000, one on 5001). I have also created two ApiControllers, with…
3
votes
2 answers

inherited class and properties not included in JSON result from ASP.NET Core API

I have a simple model that I try to serialize to JSON, but some properties don't get included in the result. When my object inherits from a base class, the properties of the base class doesn't appear in the json. In the JSON string "searchModel" is…
SteinTheRuler
  • 3,549
  • 4
  • 35
  • 71
3
votes
1 answer

ASP.NET Testing Api controller: Uri(Request.GetEncodedUrl()...) returns null

I am testing an ASP.NET Core Api post method, but I get a System.NullReferenceException causing my test to fail. The null exception appears when I try to return a Created()-ActionResult, like this: return Created(new Uri(Request.GetEncodedUrl() +…
3
votes
2 answers

ApiExplorer: How to Change The Default for IgnoreApi

We have a couple of ApiController implementations and we do not want most operations to be included in the metadata of ApiExplorer. By default, if you do not add [ApiExplorerSettings(IgnoreApi = true)] to your operation, it will be added so this…
3
votes
1 answer

How can i get User.Identity values without using the Authorize attribute?

I'm developing an api which is using JwtBearer for authentication.When I'm try to using User.Identity like this; [HttpGet] public IActionResult Detail(int id) { if(User.Identity.IsAuthenticated) { return ... …
3
votes
2 answers

How to validate type of collections?

How can I validate and catch collection type conversion (JSON string array to C# long collection) for my System.Web.Http.ApiController class (before the model is initialized if possible)? I want to validate and catch any non-numeric elements in the…
3
votes
3 answers

Core 2.0 API Auth with JWT returns unauthorized

I'm trying to add Token Authentication with JWT to my .Net Core 2.0 app. I have a simple controller that returns a list of users for testing. [Authorize] [Route("api/[controller]")] public class UsersController : Controller { ... …
pStan
  • 1,084
  • 3
  • 14
  • 36
3
votes
0 answers

Custom controller configuration changes all controllers setting

I am developing an application which uses webapi controllers. I just need to set some setting for a Specific controller not ALL! I use IControllerConfiguration and in the initialize method set type name handling setting. I expect that this setting…
3
votes
1 answer

need route for my web api 2 controller

I have a simple WebApi2 controller that returns XML but I cannot add another method properly with the routing I have defined: namespace CBMI.WebAPIservice.Controllers { public class MarkersController : ApiController { public HttpResponseMessage…
3
votes
1 answer

ApiController returning 504 - The server did not return a complete response for this request. Server returned 0 bytes

I have a call to my ApiController which is returning a 504 and I just cannot work out what I am doing wrong... Can anyone see my problem? This is the controller: public class SA_GetAllLocationsController : ApiController { …
Trevor Daniel
  • 3,785
  • 12
  • 53
  • 89
3
votes
4 answers

MVC 4 return JSON as ActionResult

i'm trying to get my apicontroller to work. But somehow i cannot return Json(). Here's the error message from the compiler: Error CS0029 Cannot implicitly convert type 'System.Web.Http.Results.JsonResult<>' to 'System.Web.Mvc.JsonResult' …
NinjaOnSafari
  • 998
  • 1
  • 8
  • 32
3
votes
1 answer

ASP NET attribute routing array

So I am using attribute routing for my controller like this: [Route("last/{id:int}")] public IHttpActionResult GetUpdateLast([FromUri] int id) { return Ok(); } Now I want to convert it to accept an array of integers, in the…
3
votes
0 answers

ProgressEvent.load is always the same as ProgressEvent.Total which causes the progress to fake

I'm trying to implement progress bar on a website. The Problem: ProgressEvent.load is always the same as ProgressEvent.Total which prevent the progress to show the real state of the upload. At the first second the xhr request does sent it looks like…
3
votes
1 answer

MVC instrumentation & WebApi attribute routing for Sitecore 7.5

I have been trying to get WebApi working with Sitecore 7.5 (I was able to get the same code working with 7.2) I have left in the config the reference to MVC 5.1 and I am getting the following exception when I try to access a route mapped with an…
1 2
3
30 31