asp.net-web-api2

Web Api 2 bad request

不打扰是莪最后的温柔 提交于 2019-12-08 04:32:01
问题 Im a beginner with Web api and Im trying to setup a simple owin selfhosted service that Im trying out. I've been searching stackoverflow and other places for a while now, but I cant seem to find anything obviously wrong. The problem I have is that I get a bad request response everytime I try to call my service. The controller looks like this: [RoutePrefix("api/ndtdocument")] public class NDTDocumentsController : ApiController, INDTDocumentsController { [HttpGet] public IHttpActionResult Get()

ExceptionFilter stack trace in synchronous action scenario

本小妞迷上赌 提交于 2019-12-08 04:31:28
问题 I have a simple synchronous action in a Controller that throws an exception like so : [RoutePrefix("")] public class MyController : ApiController { [Route("")] public HttpResponseMessage Get() { throw new Exception("whatever"); return Request.CreateResponse(HttpStatusCode.OK, "response"); } } I also have an ExceptionFilterAttribute to get a hold of exceptions that occur in the application public class MyExceptionFilterAttribute : ExceptionFilterAttribute { public override void OnException

What is the benefit(s) of self hosted web API? [closed]

爷,独闯天下 提交于 2019-12-08 04:17:58
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . Actually! I'm putting this question Just to know that what is the exact ways to host if i have a solution and there is a API project any many others? And exactly why we need self hosting? Please Guide me Thanks 回答1: I use self-hosting of web-api in windows console and windows

Removing NaN values in deserialization Web API 2 C#

南笙酒味 提交于 2019-12-08 03:56:42
问题 Hello I am wondering if anyone could help me, I am trying to automatically replace NaN from double values automatically with 0 upon deserializing automatically in Web API 2. I am trying to use JSON.NET but I am having no success. Any help would be greatly appreciated. I am placing the below into my WebApiConfig config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); MediaTypeHeaderValue appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes

Owin- Slow CompatibleWithModel call

大兔子大兔子 提交于 2019-12-08 03:47:37
问题 I have this line of code within a request of an ApiController of an Azure Mobile App Web API : var user = t.TrackDependency(() => context.Users.SingleOrDefault(x => x.Email == loginRequest.Id || x.Name == loginRequest.Id), "GetUser"); Here is the result from Application Insights: We can see that while the line of code took 2613ms, the actual query call to the database took 190ms. While this is an edge case it happens often enough to get complaining users about slow performance. The thing is I

MVC6 Web Api - Return Plain Text

▼魔方 西西 提交于 2019-12-08 02:55:51
问题 I have looked at other similar questions (such as this one Is there a way to force ASP.NET Web API to return plain text?) on SO but they all seem to address WebAPI 1 or 2, not the latest version you use with MVC6. I need to return plain text on one of my Web API controllers. Only one - the others should keep returning JSON. This controller is used for dev purposes to output a list of records in a database, which will be imported into a traffic load generator. This tool takes CSV as input so I

Issue with inheritance with WebAPI, OData v3 and BreezeJs

六眼飞鱼酱① 提交于 2019-12-08 02:45:39
问题 We are using WebAPI 2.2, with OData v3 and BreezeJS and are having an issue when using inheritance, we have a setup along the following lines (simplified obviously for this issue) We have a Vehicle abstract class and then two other classes (Bus and Car) which inherit from Vehicle, such as: public abstract class Vehicle { public int Id { get; set; } public string Name { get; set; } } public class Bus : Vehicle { public int NumberOfSeats { get; set; } } public class Car : Vehicle { public

Token based authentication for both Web App and Web API using Azure AD B2C

ぃ、小莉子 提交于 2019-12-08 01:49:08
问题 Scenario: Both Web application and Web API need to be authenticated and protected from the server side. Requirement: Web application is serving the contents for the browser and browser should be calling Web API directly (i.e. Browser to API). Question: Is it possible to authenticate both Web APP and the API using tokens? Any sample code or clear direction would be highly appreciated. Normally web applications are authenticated using cookies and APIs are authenticated using tokens.There are

.NET Core - Trying to add a repository to my API controller, but when I do every controller method returns a 500 error

好久不见. 提交于 2019-12-08 01:01:54
问题 As the title says. I'm creating a Web API and in my API controller, I'm trying to declare a repository in the constructor. I successfully declare it, but every API method I try to call in that controller returns a 500 error. When I remove the constructor/repository variable, I have no issues. Controller [Route("api/[controller]")] public class TestController: Controller { private ITestRepository _testRepository; public TestController(ITestRepository testRepository) { _testRepository=

Using Unity with Web Api 2 gives error does not have a default constructor

若如初见. 提交于 2019-12-08 00:42:26
问题 I have ASP.NET MVC5 web application and i also have Web API in the same application. I am uisng Unity (version 4) for DI. I am configuring the Unity container on APP start as below public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { UnityConfiguration.Config(); } } public class UnityConfiguration() { public void Config() { UnityContainer container = new UnityContainer(); container.RegisterType<IMyService, Myservice>(); container.RegisterType