asp.net-web-api2

WebAPI 2.0 Post Not Deserializing List<T> Property

冷暖自知 提交于 2019-12-23 16:23:51
问题 I have reviewed every similar article I can find here and tried anything that looked like it might work with no success (obv since I am now asking the question). I have a webAPI 2.0 controller with a POST action that takes in an object of type Reservation . This object contains, among other things, a property called Items which is of type EquipmentItems . As you can imagine, this is a List property. I send the reservation object over (using PostAsJsonAsync("api/Reservation", reservation)

Angular 2 AspNetCore WebApi CORS issue: Response for preflight has invalid HTTP status code 401

穿精又带淫゛_ 提交于 2019-12-23 15:44:18
问题 I am attempting to implement simple token based authentication in an Angular 2 RC6 application against an AspNetCore WebApi project that I've implemented in Visual Studio 2015. I have put my sample application on github at: https://github.com/tonywr71/Snazzle which is a fully functioning application. In the application, I click on the Login menu item, put in login and password information then click login. It successfully returns am authentication token, which I store in isolated storage. I

Why is CORS Disabled by Default?

天大地大妈咪最大 提交于 2019-12-23 12:40:54
问题 Alright, first of all, I am absolutely aware that we have a bunch of answers on this and there is a plethora of articles on the topic. I just read these answers a second before typing this: Why is CORS without credentials forbidden?. Is CORS considered bad practice? Etc. My particular situation is this - I just set up WebAPI2 for my practice project, the front end for which is running via gulp browser-sync. I have no idea how these ports get picked, but lets say the Web API is running on port

How to call Default Model Binding from custom binder in WebAPI?

安稳与你 提交于 2019-12-23 12:34:14
问题 I have a custom model binder in WebAPI that uses the following method from the `Sytem.Web.Http.ModelBinding' namespace which is the correct namespace for creating custom model binders for Web API: public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { } I have a HTTP POST on a controller for which I want to use this custom model binder. The posted object contains roughly 100 fields. I want to change 2 of them. What I need is for default model binding to

Web API 2 return OK response but continue processing in the background

女生的网名这么多〃 提交于 2019-12-23 11:53:38
问题 I have create an mvc web api 2 webhook for shopify: public class ShopifyController : ApiController { // PUT: api/Afilliate/SaveOrder [ResponseType(typeof(string))] public IHttpActionResult WebHook(ShopifyOrder order) { // need to return 202 response otherwise webhook is deleted return Ok(ProcessOrder(order)); } } Where ProcessOrder loops through the order and saves the details to our internal database. However if the process takes too long then the webhook calls the api again as it thinks it

Dapper giving “Invalid attempt to call FieldCount when reader is closed.” when trying to use “QueryMultiple”

Deadly 提交于 2019-12-23 09:58:34
问题 I have a wrapper method for Dapper.NET's QueryMultiple method. It successfully gets data from a Stored Procedure, which has 3 queries, all of them are SELECT queries. But after getting the data, I cannot use Read or ReadAsync to assign data to class variables. I'm attaching my code below. public Tuple<IEnumerable<T1>, IEnumerable<T2>, IEnumerable<T3>> QueryMultiple<T1, T2, T3>() { try { var data = MultiQuery("[App].[USP_GetAllCategories]"); var category = data.Read<T1>(); var subcategory =

Reading every incoming request (URL) in ASP.NET WEB API

孤者浪人 提交于 2019-12-23 09:27:27
问题 I was using ASP.NET MVC framework. In this framework, we checked every incoming request (url) for some key and assigned it to a property. We created a custom class which derived from Controller class & we override OnActionExecuting() to provide our custom logic. How can we achieve the same in ASP.NET WEB API? //Implementation from ASP.NET MVC public class ApplicationController : Controller { public string UserID { get; set; } protected override void OnActionExecuting(ActionExecutingContext

Web Api 2 - How to return an image (MemoryStream from Azure Storage) from a HTTPGET without saving to disk?

泪湿孤枕 提交于 2019-12-23 08:39:37
问题 I'm using Web Api 2 with C# and Azure, and having issues with how to return the image (base from Memorystream) for displaying on the page... Here is my Controller HTTPGET [Route("api/PhotoSubmit/GetPhoto/{id}")] [HttpGet] public HttpResponseMessage GetPhotoById(int id) { StorageServices storage = new StorageServices(); MemoryStream ms = storage.DownloadBlob(id); // return what ? } Here is the beginning of the servicecall : $http({ method: 'GET', url: 'api/PhotoSubmit/GetPhoto/' + $routeParams

Microsoft Owin Logging - Web Api 2 - How do I create the logger?

旧城冷巷雨未停 提交于 2019-12-23 07:22:40
问题 I am trying to add logging to my app using Web Api 2 and Owin, so I started using Microsoft Owin Logging, which requires an ILogger and ILoggerFactory , that has been implemented and it works great when I need to log anything inside the STARTUP method or any of the Owin Middleware components. For example, when I am in the Startup method I can create the logger using: public void Configuration(IAppBuilder app) { // Creates configuration var configuration = new HttpConfiguration(); // Configure

Asp.net core web api using windows authentication - Cors request unauthorised

僤鯓⒐⒋嵵緔 提交于 2019-12-23 07:20:07
问题 In my asp.net core web api, I've configured Cors as per the article from MS documentation. The web api app is using windows authentication (Anonymous Authentication is Not enabled). Cor's policy is created and middle ware is added as below in the startup.cs public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.WithOrigins("http://localhost:4200") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() ); }