asp.net-web-api

client.DeleteAsync - include object in body

可紊 提交于 2020-02-24 09:17:30
问题 I have an ASP.NET MVC 5 website - in C# client code I am using HttpClient.PutAsJsonAsync(path, myObject) fine to call a Json API (the API is also mine created in Web API). client.BaseAddress = new Uri("http://mydomain"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PutAsJsonAsync("api/something", myObj); I would like to do the same with a Delete verb. However client

Value tuples expose wrong parameter name from WebAPI

纵饮孤独 提交于 2020-02-24 00:38:26
问题 I'm using web api. I've been a bit lazy and decided to return a value tuple from my controller. [HttpGet] [Route(AuthAPIRoutes.GET_MFA_DEVICES)] public (string Type, string Value)[] GetMultiFactoryMethods() { return GlobalFactory<IPaystreamMFASecurityService>.Instance.GetMultiFactorMethods(); } The JSON response doesn't seem to be using the appropriate naming is this being optimized away? { "item1": "Phone", "item2": "1-512-555-0550" } NOTE: I'm aware I can explicitly make a model to avoid

Post Array Json to .net core web api controller [duplicate]

拥有回忆 提交于 2020-02-21 10:37:30
问题 This question already has answers here : how to post json object array to a web api (3 answers) Closed 2 years ago . I have this code [HttpPost("[action]")] public IActionResult Add([FromBody] Player player) { PlayerService.Add(player); PlayerService.SaveChanges(); return Created("Player created",player.Name); } and this json [ { "name": "Olivier Giroud", "league": "Premier League", "currentTeam": "Arsenal" } ] and everything is going ok. But if i want to send a json array [ { "name":

Post Array Json to .net core web api controller [duplicate]

孤人 提交于 2020-02-21 10:36:29
问题 This question already has answers here : how to post json object array to a web api (3 answers) Closed 2 years ago . I have this code [HttpPost("[action]")] public IActionResult Add([FromBody] Player player) { PlayerService.Add(player); PlayerService.SaveChanges(); return Created("Player created",player.Name); } and this json [ { "name": "Olivier Giroud", "league": "Premier League", "currentTeam": "Arsenal" } ] and everything is going ok. But if i want to send a json array [ { "name":

Web API action filter content can't be read

你离开我真会死。 提交于 2020-02-19 03:58:33
问题 Related question: Web API action parameter is intermittently null and http://social.msdn.microsoft.com/Forums/vstudio/en-US/25753b53-95b3-4252-b034-7e086341ad20/web-api-action-parameter-is-intermittently-null Hi! I'm creating a ActionFilterAttribute in ASP.Net MVC WebAPI 4 so I can apply the attribute in action methods at the controller that we need validation of a token before execute it as the following code: public class TokenValidationAttribute : ActionFilterAttribute { public override

Web API action filter content can't be read

血红的双手。 提交于 2020-02-19 03:58:25
问题 Related question: Web API action parameter is intermittently null and http://social.msdn.microsoft.com/Forums/vstudio/en-US/25753b53-95b3-4252-b034-7e086341ad20/web-api-action-parameter-is-intermittently-null Hi! I'm creating a ActionFilterAttribute in ASP.Net MVC WebAPI 4 so I can apply the attribute in action methods at the controller that we need validation of a token before execute it as the following code: public class TokenValidationAttribute : ActionFilterAttribute { public override

error writing mime multipart body part to output stream

夙愿已清 提交于 2020-02-18 07:40:08
问题 I have code that does async file uploads which works fine on my dev vm but after I deployed it to the client system, I keep getting this error: "error writing mime multipart body part to output stream" I know this is the line that is throwing the error but I can't seem to figure out why: //Read the form data and return an async task. await Request.Content.ReadAsMultipartAsync(provider); The file size was only 1MB and I even tried different file types with much smaller sizes. Why would this

DateTime Json Return From WebAPI with Default Serializer

◇◆丶佛笑我妖孽 提交于 2020-02-17 06:35:09
问题 I know this question has been hashed over multiple times and I read lots of posts on that hashing but still am confused. Using MVC4/WebAPI, I have a datetime that is simply created as new DateTime.Now. My WebAPI is return data like this: HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, new { data = sessionRecordSmalls, count = sessionRecordSmalls.Count, success = true }); where sessionRecordsSmall has a public property of DateTime in it. When I look at the date in the

Anti forgery with token API and angular

て烟熏妆下的殇ゞ 提交于 2020-02-16 08:23:13
问题 I am working on Angular 6 application with SSO login and .net core web API. The code hits the back end on /token url first time which is a post operation. How do I do the anti forgery in this scenario. Please explain the flow of token transfer 回答1: I'm not sure if that's what you're looking for, but I'll try to explain how I achieved it in a similar case. First of all Angular has built in helpers for XSRF handling: https://angular.io/guide/security#http https://angular.io/api/common/http

Anti forgery with token API and angular

只谈情不闲聊 提交于 2020-02-16 08:23:09
问题 I am working on Angular 6 application with SSO login and .net core web API. The code hits the back end on /token url first time which is a post operation. How do I do the anti forgery in this scenario. Please explain the flow of token transfer 回答1: I'm not sure if that's what you're looking for, but I'll try to explain how I achieved it in a similar case. First of all Angular has built in helpers for XSRF handling: https://angular.io/guide/security#http https://angular.io/api/common/http