asp.net-web-api

Model validation - Why ModelState.IsValid always returns true even when no values are supplied?

点点圈 提交于 2020-01-03 06:19:09
问题 This is regarding WEBAPI and the following is my Model class. public class Request { public int Id { get; set; } public string Name { get; set; } [Required] public Gender Gender { get; set; } } And my controller function (POST) public class Values1Controller : ApiController { public IHttpActionResult Post([FromBody] Models.Request request) { if (!ModelState.IsValid) { return BadRequest(); } var gender = request.Gender; var id = request.Id; var name = request.Name; // do some operations!

I know about uploading in chunks, do we have to do something on receiving end?

巧了我就是萌 提交于 2020-01-03 05:19:18
问题 my azure function receives large video files and images and stores it in Azure blob. Client API is sending data in chunks to my Azure htttp trigger function. Do I have to do something at receiving-end to improve performance like receiving data in chunks? Bruce, actually Client code is being developed by some other team. right now i am testing it by postman and getting files from multipart http request. foreach (HttpContent ctnt in provider.Contents) { var dataStream = await ctnt

I know about uploading in chunks, do we have to do something on receiving end?

十年热恋 提交于 2020-01-03 05:19:02
问题 my azure function receives large video files and images and stores it in Azure blob. Client API is sending data in chunks to my Azure htttp trigger function. Do I have to do something at receiving-end to improve performance like receiving data in chunks? Bruce, actually Client code is being developed by some other team. right now i am testing it by postman and getting files from multipart http request. foreach (HttpContent ctnt in provider.Contents) { var dataStream = await ctnt

Castle Windsor DI installer: dependency factory method has nested dependency on ApiController property

你说的曾经没有我的故事 提交于 2020-01-03 05:18:08
问题 I am trying to implement DI with Castle Windsor. Currently I have a controller with overloaded constructors like this (this is an antipattern as described here: https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=97): public class MyController : ApiController { protected IStorageService StorageService; protected MyController() { StorageService = StorageServiceFactory.CreateStorageService(User.Identity as ClaimsIdentity); } protected MyController(IStorageService storageService) {

Unit Testing ASP.NET Web API

瘦欲@ 提交于 2020-01-03 05:08:08
问题 I'm unit testing a simple post: public HttpResponseMessage<Document> PostDocument(Document document) { document = repository.Add(document); var response = new HttpResponseMessage<Document>(document, HttpStatusCode.Created); var uri = Url.Route(null, new { id = document.Id }); response.Headers.Location = new Uri(Request.RequestUri, uri); return response; } However, the 'URL' and 'Request' are obviously going to be null. Is there an alternative to mocking out ControllerContext and HttpContext?

How to get connection string from appsettings.json inside custom filter in .net core

左心房为你撑大大i 提交于 2020-01-03 04:53:07
问题 I have a controller EBisUserController which contains a public property ConnectionString obtained from appsettings.json through dependency injection. The controller has an attribute filter 'EBisUserAuthResourceFilter' requiring use of the property ConnectionString found in the controller. What is the most performant method to access ConnectionString. I have a working example of what I want, but know this is not the correct way of doing this as it must open and read the file for each

is it possible to get an offline version of swagger documentation for a website?

时光毁灭记忆、已成空白 提交于 2020-01-03 03:35:10
问题 localhost/swagger is loading as expected for me but remoteserver/swagger is having issues. Is it possible for me to save an offline copy of the swagger documentation that's generated? I can just send a zip file to a few users while I'm trying to debug the remote issue. 回答1: There are lots of ways to provide API docs to your users if you for some reason cannot host Swagger UI yourself. All suggestions assume you have an OpenAPI (Swagger) definition, that is the YAML/JSON file. If you don't

.NET Web Api - several GET and POST methods

不羁岁月 提交于 2020-01-03 02:59:32
问题 I'm writing a REST API and have the following problem: With the resource /messages/, I have the following methods in my MessageController: [HttpGet] // retrieves all messages for a user public HttpResponseMessage GetMessages(Guid RecordId) {} [HttpGet] // retrieves only a single messages, specified by guid public HttpResponseMessage GetMessage(Guid RecordId) {} In my WebApiConfig.cs I have the following routing: config.Routes.MapHttpRoute( name: "MessageRouting", routeTemplate: "messages/

How to refresh the list of items after deleting one item using AngularJS?

六眼飞鱼酱① 提交于 2020-01-03 02:56:08
问题 I am a new to AngularJS area and I am trying to use it with ASP.NET Web API. I am struggling right now with the Delete Function. The user should be able to delete an item from a list of items and when he deletes an item successfully, the list should be updated (or refreshed) immediately after that deletion. I already implemented the deletion function, however, the list doesn't get updated after the deletion and I don't know why. Here's the code of deletion function in Web API: // DELETE api/

IIS Express (WebMatrix 2) won't serve .cshtml files in WebAPI project (VS10/WinXP)

帅比萌擦擦* 提交于 2020-01-03 02:51:05
问题 I am trying to run a WebAPI project on WinXP through WebMatrix 2. I'm getting this error when attempting to browse index.cshtml (in the root): "This type of page is not served." I created a WebAPI project under the MVC4 project type in Visual Studio 2010, then set the project to run under IIS Express. What I've Tried: The .NET CLR settings in the VS-created WebMatrix site is .NET 4.0 (Integrated). I've already tried playing with the runAllManagedModulesForAllRequests setting in Web.config, no