asp.net-core-webapi

Asp.net Core Post parameter is always null

独自空忆成欢 提交于 2020-01-14 07:32:28
问题 I'm sending POST from fiddler: POST http://localhost:55924/api/Product HTTP/1.1 User-Agent: Fiddler Host: localhost:55924 Content-Type: application/json; charset=utf-8 Content-Length: 84 {"Ean":"1122u88991","Name":"Post test","Description":"Post test desc"} But Post method always gets null. // POST api/Product [HttpPost] public IActionResult PostProduct([FromBody]Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _repo.Add(product); return CreatedAtRoute("GetToode"

Disable AutoRedirect in FlurlClient

依然范特西╮ 提交于 2020-01-13 09:39:12
问题 I am using FlurlHttp and I want to disable AllowAutoRedirect for some API calls. I know How can I get System.Net.Http.HttpClient to not follow 302 redirects? WebRequestHandler webRequestHandler = new WebRequestHandler(); webRequestHandler.AllowAutoRedirect = false; HttpClient httpClient = new HttpClient(webRequestHandler); // Send a request using GetAsync or PostAsync Task<HttpResponseMessage> response = httpClient.GetAsync("http://www.google.com") But for Flurl I found only the way similar

Json.Net and validation of Enums in Web API

旧时模样 提交于 2020-01-10 05:40:09
问题 I'm writing a web api in .Net Core 2.2. I have an enumeration as follows: using System.Runtime.Serialization; namespace MyNamespace { public enum MyEnum { [EnumMember(Value = "Some Value")] SomeValue } } If I pass in random data as MyEnum in a request using the enum I rightly get an error, but if I pass "Some Value" or "SomeValue" it passes. How do I make "SomeValue" invalid? "SomeValue" isn't in my swagger and isn't a value I want to accept. So basically, model validation passes for

XUnit Net Core Web API Integration Test: “The ConnectionString property has not been initialized.”

不羁的心 提交于 2020-01-06 08:46:15
问题 Just trying to build an Integration Test project for a NET Core Web API. So I've followed a few examples, including this one (https://dotnetcorecentral.com/blog/asp-net-core-web-api-integration-testing-with-xunit/) and naturally, I run into issues. When I run the simple GET test I get an exception: "System.InvalidOperationException : The ConnectionString property has not been initialized." Any help would be appreciated. 回答1: For server = new TestServer(new WebHostBuilder().UseStartup<Startup>

WebApi Application_Start will not fire until web page is loaded or SignalR request is made

为君一笑 提交于 2020-01-06 07:07:31
问题 I have WebApi OWIN hosted Web Server/Winforms Client application. Additionally I am using SignalR for client/server communication. When running under IIS Express while debugging Application_Start method in Global.asax.cs is executing just fine. On IIS 7.5 same code in Global.asax.cs will not execute when website is started in IIS Manager Application_Start only fires when I call it from a page http://localhost:7000/SignalR/hubs or Client sends SignalR request first time around and after that

Route to allow a parameter from both query string and default {id} template

点点圈 提交于 2020-01-06 04:56:07
问题 I have an action in my ASP.Net Core WebAPI Controller which takes one parameter. I'm trying to configure it to be able to call it in following forms: api/{controller}/{action}/{id} api/{controller}/{action}?id={id} I can't seem to get the routing right, as I can only make one form to be recognized. The (simplified) action signature looks like this: public ActionResult<string> Get(Guid id) . These are the routes I've tried: [HttpGet("Get")] -- mapped to api/MyController/Get?id=... [HttpGet(

How to download files using axios.post in React using webapi Core

人走茶凉 提交于 2020-01-06 04:41:10
问题 I have used this How to download files using axios.post from webapi (It could be duplicate of this) to work on this scenario but i am not getting success. React: axios.post("URL",{data:data, responseType: "blob"}) In response i am getting corrupted data, not bytes. ResponseType works with get request but why not with post? WebAPI Core: return File(arraybytes, "application/vnd.openxmlformats- officedocument.spreadsheetml.sheet", "test.xlsx"); 来源: https://stackoverflow.com/questions/55901499

c# HttpResponseMessage.Content does not return MemoryStream correctly to HttpClient but using byte[] for return works

孤人 提交于 2020-01-06 04:38:08
问题 I am trying to use HttpClient.PostAsync to submit data to a Controller and then return a Bitmap in Memorystream created by QRCoder to HttpClient via IActionResult . If the Controller returns byte[] , the response.Content.ReadAsStringAsync().Result gets the correct MemoryStream data. However, if the Controller returns IActionResult , neither response.Content.ReadAsStringAsync().Result , response.Content.ReadAsByteArrayAsync().Result , response.Content.ReadStreamAsync() provides the expected

Custom Webhook Receiver in .Net core 2.1

不打扰是莪最后的温柔 提交于 2020-01-05 06:14:45
问题 I'm trying to create webhooks receiver for bigcommerce webhooks. [HttpPost("customer_update")] public void GetCustomerUpdateHook() { d_logger.Information("Process Webhook reply Web Response Hit"); } my function is getting hit without any issues. But I don't know how to access the receiving data. I'm not sure how to use WebHookHandler. framework => .Net core 2.1 controller => API Controller 回答1: I was able to receive the data, without using webhook handler or receiver. I just created a "POST"

Bearer token WEB API asp.net core without redirection

≡放荡痞女 提交于 2020-01-05 05:39:09
问题 I'm new to asp.net core. I'm trying to make a small web service using jwt authentication and OpenOauth from Google , Facebook, ... I've read this post : https://stormpath.com/blog/token-authentication-asp-net-core This post is about authenticating with jwt in ASP.Net core, but, I also want to verify whether the user is disabled or active in my system . My db has one table with 4 columns: Id, Name, Password, Status (0 - Disabled | 1 - Active). How can I archieve my goal ? Can anyone help me