asp.net-web-api

`visual studio 2017 add as link content files (aspnetcore)

时光毁灭记忆、已成空白 提交于 2020-01-01 06:46:29
问题 Since VS2017 returned to csproj, I am again able to add files "as link"... NOT! When I link a file I also want it to be copied to the solution folder (not output directory, just solution), for example js files, webpack config files etc, I have them shared and "linked". But in order for these to be really "seen" by visual studio, I have to copy them to the solutions. I do this in a BeforeTargets="Build" event in the csProj file. That is how I did it before the project.json change (during the

Routing an Angular 2 app with Web API

拜拜、爱过 提交于 2020-01-01 05:45:09
问题 I have an Angular 2 application created with Angular CLI. This has to call a .NET 4.6 Web API. The route setup of this is driving me nuts. For Angular, the default folder for output is /dist . Angular CLI does all the minification and tree-shaking you can dream of and then outputs both its JavaScript files and index.html to that folder. So if I run index.html , those files are retrieved from the same folder. Everything works well, because index.html contains a tag like this one: <base href="/

EF5 code first with ASP.NET Web API: Update entity with many-to-many relationship

穿精又带淫゛_ 提交于 2020-01-01 05:23:12
问题 I'm trying to update a Customer in my database using ASP.NET Web API and Entity Framework 5 code-first, but it's not working. My entities look like this: public class CustomerModel { public int Id { get; set; } public string Name { get; set; } // More fields public ICollection<CustomerTypeModel> CustomerTypes { get; set; } } public class CustomerTypeModel { public int Id { get; set; } public string Type { get; set; } [JsonIgnore] public ICollection<CustomerModel> Customers { get; set; } }

What are the benefits of async webservices when not all parts of the code is async

梦想的初衷 提交于 2020-01-01 05:08:26
问题 I am wondering how much benefit you get from using async http requests if not all parts of your code is async. Lets consider to scenarios: 1) async http requests blocking on sync database calls, and 2) sync http requests awaiting async database calls. 1) Web Api supports async action methods, but if I do a sync database call when handling the request, then the thread blocks on the call, and I will not get the benefits of better thread economy that async could give me or what? 2) If I have a

ASP.NET Web Api - the framework is not converting JSON to object when using Chunked Transfer Encoding

為{幸葍}努か 提交于 2020-01-01 04:55:08
问题 I have an http client in Android sending HTTP PUT requests to a REST api implemented with C# and ASP.NET WebApi framework. The framework should be able to magically convert (deserialize) the JSON into a model class (plain object) as long as the JSON fields match the properties in the C# class. The problem comes when the http requests come with Chunked Transfer Encoding that makes the Content-Length = 0 (as per http://en.wikipedia.org/wiki/Chunked_transfer_encoding) and the framework is not

Adding Web API and API documentation to an existing MVC project

我只是一个虾纸丫 提交于 2020-01-01 04:31:08
问题 I have successfully added a web api controller to an existing MVC4 application. I would like to have the api documentation functionality as is available in the new web api samples (ex. http://sample.hostname.com/help) . I believe these use the ApiExplorer class. I tried just copying the HelpPage area into my project, but I get an error "The type String cannot be constructed. You must configure the container to supply this value" when I try to navigate to help. What must I do to add automated

Asp.net webapi enum parameter with default value

邮差的信 提交于 2020-01-01 04:28:07
问题 I have a controller [HttpGet] [RoutePrefix("api/products/{productId}")] public HttpResponseMessage Products(int productId,TypeEnum ptype=TypeEnum.Clothes) { if(!Enum.IsDefined(typeOf(TypeEnum),ptype)) //throw bad request exception else //continue processing } Myenum is declared as public TypeEnum { Clothes, Toys, Electronics } Currently if,some garbage value is passed it is getting converted into default value. What I want to do is if i call the controller as api/products/1 then the ptype

Remove <ArrayOf. From MVC Web Api response

拥有回忆 提交于 2020-01-01 04:25:15
问题 I am getting the following response from a standard MVC 4 WebApi project; <ArrayOfProduct xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Product> <Id>1</Id> <Name>Tomato Soup</Name> <Category>Groceries</Category> <Price>1</Price> </Product> </ArrayOfProduct> I am trying to make it so that it returns <Products> <Product> <Id>1</Id> <Name>Tomato Soup</Name> <Category>Groceries</Category> <Price>1</Price> </Product> </Products> I have found

Are Microsoft.Owin types like OwinMiddleware and IOwinContext incompatible with other Owin servers?

假如想象 提交于 2020-01-01 04:11:07
问题 If I build an OWIN middleware using Microsoft.Owin types like OwinMiddleware and IOwinContext, would my middleware work with non-Microsoft Owin hosts/servers? I'm looking at the middleware classes for Nancy and SignalR and they seem very different from the OwinMiddleware base class that middlewares like the Cookie authentication middleware and WebApi is based on. I'm reading the spec but I'm still not clear if a non-Microsoft Owin server could work with the OwinMiddleware and IOwinContext

ASP.NET Web API Authorization with Postman

孤人 提交于 2020-01-01 03:27:05
问题 I have created an ASP.NET Web API and applied Authorize attribute to the API controller. Now, I want to test it using Postman but I am getting Authorization error. Controller code is: [Authorize] [HttpPost] public IHttpActionResult Attend([FromBody] int gigId) { var attendance = new Attdendance { GigId = gigId, AttendeeId = User.Identity.GetUserId() }; _context.Attdendances.Add(attendance); _context.SaveChanges(); return Ok(); } My request looks like this http://prntscr.com/c8wz0b I am using