asp.net-web-api2

Large file upload when using ssl and client certificates (uploadReadAheadSize) but dont want all data to be readahead

一世执手 提交于 2019-12-09 17:37:03
问题 I tried to search the internet/stack overflow and couldn't find any relevant answer that worked for me. I have an asp.net web api2 application (uses ssl only). I'm trying to allow large file upload (up to ~36mb) but unless i change uploadReadAheadSize to readahead this size I get an error from IIS that the request is too long. I don't want to set that attribute because then my data stream only arrives after IIS read it all already. My question is: How can I do large file upload with asp.net

Web API 2 Http Post Method

不问归期 提交于 2019-12-09 14:42:41
问题 I am disgusted not have found a solution to this problem. I started creating a new api using Web API 2 and just cannot get the POST and PUT to work. The Get all and Get single item works perfectly fine. There are no related articles anywhere, and those that i've found relates only to Gets and Web API, but not Web API 2. Any assistance would do please. // POST: api/checkOuts [HttpPost] [ResponseType(typeof(checkOut))] [ApiExplorerSettings(IgnoreApi = true)] public async Task<IHttpActionResult>

Convert File to byte array Angular 2

旧时模样 提交于 2019-12-09 13:57:59
问题 How can I convert input file(image,for example) to byte array by using Angular2 ? Maybe someone can say what is better: convert image to byte array and send it to Web API or send the File "object" to API and there convert it? 回答1: You wouldn't really use Angular for solving this task. JavaScript has APIs for handling File data, e.g. https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer See this question PS: "Angular 2" is just called "Angular" now, because they're on

Exception Handling in ASP.NET Web Api 2

Deadly 提交于 2019-12-09 10:51:05
问题 Problem: I need to handle web api 2 exceptions and return a rich object with the correct status code (401 for Unauthorized, 404 for ContentNotFound, etc) and some extra information as the content. Moreover, I need the content to look like a serialized Exception object (have the message , exceptionMessage , stackTrace , ... properties). Suggested Solutions: Create custom exception classes and writing a custom exception filter to apply to any controller's action. this custom exception filters

Return an object along with a 409 Conflict error in a Web API 2 POST call backed by Entity Framework?

删除回忆录丶 提交于 2019-12-09 08:05:18
问题 I have a C# Entity Framework Web API 2 controller . Currently when an attempt is made via the POST method to create an object with the same text for the main text field, I return a 409 Conflict error as an StatusCode result to indicate the addition is considered a duplicate. What I'd like to do is return the server side object that triggered the duplicate error too. So I need something akin to the Ok() method but a variant that returns a 409 Conflict error as the HTTP status code instead of

Modular ASP.NET Web API: how to add/remove route at run time to a Web API

谁都会走 提交于 2019-12-09 05:59:45
问题 I am trying to design a modular Web API application (It is not an MVC app!) in which a user in admin role can add or remove modules without restarting the ASP.NET application. Module: each module is an assembly (.dll file) that contains at least one class which is derived from ApiController . Routing is based on Attribute Routing in ASP.NET Web API 2 Production of modules (assemblies) is not in the scope of this question. Modules (assembly files) are copied to / deleted from `~/plugins/

Add a custom response header in ApiController

我们两清 提交于 2019-12-09 04:39:23
问题 Until now, I had a GET method that looked like the following: protected override async Task<IHttpActionResult> GetAll(QueryData query) { // ... Some operations //LINQ Expression based on the query parameters Expression<Func<Entity, bool>> queryExpression = BuildQueryExpression(query); //Begin to count all the entities in the repository Task<int> countingEntities = repo.CountAsync(queryExpression); //Reads an entity that will be the page start Entity start = await repo.ReadAsync(query.Start);

Exception in HttpControllerDispatcher

谁说胖子不能爱 提交于 2019-12-08 23:04:37
In my WebApiConfig::Register(...) I replaced the HttpControllerSelector with my own controller selector. When I fire off a POST request the SelectController member is correctly called and I return a ControllerDescriptor with the correct type of my controller. But then HttpControllerDispatcher is raising an exception saying "The given was not present in the dictionary." Anyone has an idea how to debug such error? The complete exception is message is: The given key was not present in the dictionary.","ExceptionType":"System.Collections.Generic.KeyNotFoundException","StackTrace":" at System

Cant hit breakpoint in web api controller

非 Y 不嫁゛ 提交于 2019-12-08 20:23:21
问题 When i try to debug this code : // POST: api/Events [HttpPost] public async Task<IActionResult> PostEvent([FromBody] object savedEvent) { Event addedEvent = JsonConvert.DeserializeObject<Event>(savedEvent.ToString()); if (!ModelState.IsValid) { return BadRequest(ModelState); } Cant hit this line : Event addedEvent = JsonConvert.DeserializeObject<Event>(savedEvent.ToString()); Debuger reacts like i hit continue but code past doesnt execute. Im really confused. Thanks for your help. 回答1: Try

Can't get error message on BadRequest in Web Api 2

牧云@^-^@ 提交于 2019-12-08 19:22:51
问题 I've googled a lot searching for an answer to my problem with no luck so, let's try if someone else can help me. I have a Web Api 2 action to register an user after doing some validations. If everything works, it return the serialized user and if don't, an error message sent within a BadRequest response. At the other hand, I have a WPF client that calls the API for a response. My problem is that I can't get the reason sent by the error, the client just get the Bad Request error message. This