asp.net-web-api2

F# record with option field doesn't deserialize properly in Asp.Net WebApi 2.x app

落爺英雄遲暮 提交于 2019-12-11 01:19:09
问题 I have a C# Asp.Net MVC (5.2.7) app with support for WebApi 2.x targeting .Net 4.5.1. I am experimenting with F# and I added an F# library project to the solution. The web app references the F# library. Now, I want to be able to have the C# WebApi controller return F# objects and also save F# objects. I have trouble serializing a F# record with an Option field. Here is the code: C# WebApi controller: using System; using System.Collections.Generic; using System.Linq; using System.Net; using

What to return when a route/url is found but not the resource behind it?

你离开我真会死。 提交于 2019-12-11 00:53:06
问题 When a route customer/1 exists but the resource/entity behind the customer search does not exist, Should I return a 404? I mean the route exists... or should I return a 204 (No content) because I could not find a customer and the result is empty. Microsoft sample: public IHttpActionResult Get (int id) { Product product = _repository.Get (id); if (product == null) { return NotFound(); // Returns a NotFoundResult } return Ok(product); // Returns an OkNegotiatedContentResult } In my opinion a

Error 500 on Post new entity with TableController and AzureMobileApps

回眸只為那壹抹淺笑 提交于 2019-12-11 00:40:08
问题 I'm experiencing a problem using TableController on AzureMobileApps. I've created a new Azure Mobile App TableController in visual studio using scaffolding. In post I modified the resulting code adding an attach on the dbContext to avoid creating referenced item during insert on the child table. That's the resulting code: public async Task<IHttpActionResult> PostLocation(Location item) { _context.Accounts.Attach(item.LocationAccount); _context.Categories.Attach(item.PrimaryCategory); Location

Autofac, Owin and memory leaks. Is autofac leaking with owin?

梦想的初衷 提交于 2019-12-10 23:39:38
问题 Recently I realized there is a leak in my Web API application based on Owin and Autofac. The leak is not permanent but memory kept longer than per request. Here's the deal: 1-) By default Web API uses buffered responses and the runtime keeps OverlappedData structure up to 40 instances as an object pool even after the response is returned. (For performance reasons I guess) 2-) Each OverlappedData structure keeps the OwinContext alive (only 40 at a time probably for pooling) 3-) Because

How to pass object as parameter in Web Api

早过忘川 提交于 2019-12-10 23:04:02
问题 I want to pass object as parameter in my web api GET and POST method. My code is, [HttpGet] [Route("mytest/list/{model}")] public IHttpActionResult GetAllTypes(TestModel model) { //my logic here } When I call this, console get an error its not found. I tried this, [HttpGet] [Route("mytest/list/{model?}")] public IHttpActionResult GetAllTypes(TestModel model) { //my logic here } But, the parameter object gets null value. 回答1: Don't pass an object via GET. POST an object and use [HttpPost]

How to version and configure WebApi with multiple aliases

落爺英雄遲暮 提交于 2019-12-10 22:28:55
问题 Currently I am do not have any informationabout my WebApi version in url. So all my endpoings looking like this http://mywebapi/api/getsomethig/id I wan to have verson number in WebApi url as well but also want to keep the current alias. Is there a way I can configure my WebApi like that so it can respond with different aliaes: http://mywebapi/api/getsomethig/id http://mywebapi/api/v2.0/getsomethig/id http://mywebapi/api/v2/getsomethig/id What is the best approach of doing that? 来源: https:/

Swagger-Net Shows controller name instead of endpoint method

淺唱寂寞╮ 提交于 2019-12-10 22:01:21
问题 I've been trying to figure out why Swagger-Net does not show the endpoint methods in a controller. The C# project is using a Web API template based on .Net framework 4.6.1. I get the same result when I use SwashBuckler, so it's not Swagger-Net that's the issue, but something that is not configured or missing. The SwaggerConfig looks like this public class SwaggerConfig { /// <summary> /// /// </summary> public static void Register() { var thisAssembly = typeof(SwaggerConfig).Assembly;

Call WebApi controller from another controller

一世执手 提交于 2019-12-10 21:53:13
问题 So I have two projects in my solution. Both are WebApi. I have controllers in both and I can call them from the client side - javascript. The problem is that I need to call a method in the controller of the second project from method in the controller of the first project. I also think I should state that the method I need to call is Post so I need to send it parameters as well. Is this possible at all? I heard about "RedirectToAction" method but I think this won't work in webapi. 回答1: You

How to build and publish .NET MVC and Web API projects to their different folders

拜拜、爱过 提交于 2019-12-10 20:25:08
问题 I have a solution which contains MVC and WebApi projects. What I want to do is to to publish them both with a single click. I would like MVC project to go to a root folder ..\MyApp\ and WebApi to ..\MyApp\Api\ . I think I've seen such solution, but I just cannot find it any where. 回答1: The physical path is going to be determined by your publishing method. You could set up the publishing wizard to just point to the physical path that you want. Then you'd have to configure IIS to ensure that

404 response appended to webapi response

你。 提交于 2019-12-10 20:14:58
问题 I have managed to get TWO responses for a single web request: My webapi response ( a simple string with 200 status code) a 404, from what looks like a static file handler Screenshot from chrome: My setup is: F# Mono on Ubuntu 15.10 xsp4 as the web server Owin as the routing engine As you can see from the screenshot the correct response is printed (sometimes - sigh) on the first line of the browser's reponse, and then immediately followed on the page by the standard 404 page. Startup code: