asp.net-core-webapi

I can't use json to make a Post request to my web api using react

余生颓废 提交于 2019-12-13 04:19:55
问题 I created a webapi in ASP.NET Core, and I need to consume it using React, the web api works normally, if I use curl or postman among others, it works normally. The problem starts when I'm going to use React, when I try to make any requests for my API with js from the problem. To complicate matters further, when I make the request for other APIs it works normally, this led me to believe that the problem was in my API, but as I said it works with others only with the react that it does not. I

(System.IO.FileNotFoundException) .Net core Web API cannot find child dependency (Dependencies of dependency) when added DLL by “Add Reference”

蹲街弑〆低调 提交于 2019-12-13 03:45:11
问题 I am getting System.IO.FileNotFoundException in my .Net Core Web API. So I've set up the below project to demonstrate the problem. I created a.Net Standard library named DemoLibrary and added QRCoder dependency via NuGet. Disclaimer: Reason for choosing the QRCoder is that the Web API doesn't use it by default. I don't use it in my project. In fact, I'm getting this exception for EntityFrameworkCore. I created a new .Net Core Web API DemoWebAPI which has no other dependencies. Then added the

How could I get months week number based on year week number (i.e week 33)

。_饼干妹妹 提交于 2019-12-13 03:19:13
问题 I'm wondering how can I calculate what is the week of the month based on the ordinal number of the week of the year. For example I'm dealing with week 33, I should know that's Week 2 in august. I allready calculated months but now I'm dealing with weeks. I allready have a solution, but it seems dirty to me.. Here's the code: var data = query.GroupBy(x => CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(x.CreatedDate ?? DateTime.UtcNow, CalendarWeekRule.FirstDay, DayOfWeek.Monday)) .Select

WebApi Authorize attribute with services.AddIdentity returns 404 Not Found

て烟熏妆下的殇ゞ 提交于 2019-12-12 20:06:50
问题 I have a simple WebApi project, which uses IdentityServer4.AccessTokenValidation to validate tokens issued by an IdentityServer4 Server at development address: https://localhost:44347 I get the token by sending following data to identityserver: POST https://localhost:44347/connect/token client_id:x.api.client client_secret:secret response_type:code id_token scope:X.api grant_type:client_credentials Response is: { "access_token": "THETOKEN", "expires_in": 1209600, "token_type": "Bearer" } and

Accessing MVC DI Service inside other services

泄露秘密 提交于 2019-12-12 17:05:38
问题 I am constructing a HealthAPI Class Library Which provides a list of statistics to our HealthMonitor Service. I have successfully got this working, The Middleware is recording Service boot time and recording response times, our health monitor is able to parse these values via a call to a our StatusController which has a number of actions returning IActionResult JSON responses. We intend to reuse this over all of our services so have opted to keep the API controller within the Class Library

Add text to URLs instead of int ID

核能气质少年 提交于 2019-12-12 15:35:27
问题 At the moment our permalinks are not correct and hinder searching e.g. https://example.com/en/blogs/19 - this should have words in the URL that Google can pick up in the search, instead of a int id that is used to retrieve from Db. Let's say an article for 'The Automotive Industry Latest' Google will give more weight in the algorithm if we had the ability to edit the link that included keywords. For example: https://example.com/en/blogs/news/The_Automotive_Industry_Latest - this link should

FromHeader Asp.NET Core binding to default value

时光怂恿深爱的人放手 提交于 2019-12-12 14:54:46
问题 I'm testing Asp.Net core WebApi with the following basic controller: [Route("test")] public class TestController { [Route("mult")] [HttpGet] public int Multiply(int x, int y) { return x * y; } } Then, in Fiddler, I send the following request: And, for some reason, the response is 0. Both x and y are binded to the default integer value when entering the method. I also tried: [Route("test")] public class TestController { [Route("mult")] [HttpGet] public int Multiply([FromHeader]int x,

ASP.NET-Core 2.0 Add/remove routes after application has already started

感情迁移 提交于 2019-12-12 14:10:32
问题 I have a need to add/remove custom routes that were registered during the Configure() method of the Startup class via the IApplicaitonBuilder. Upon startup I call the MapRoute method within the UseMvc command to register a bunch of custom routes to my controllers which all work as expected. I would like to create a route management feature that allows the administrator of the API to enable/disable these custom routes which means I need the ability to add/remove routes after the application

Authentication in dot net core preview-2.0

戏子无情 提交于 2019-12-12 13:34:18
问题 I tried jwt token authentication in my web api project in .net-core preview-2, but it's not working properly. JwtBearerAppBuilderExtensions.UseJwtBearerAuthentication(IA‌​pplicationBuilder, JwtBearerOptions)' is obsolete: 'See go.microsoft.com/fwlink/?linkid=845470'; When i try same code to dot net core 1.2, it runs properly. What should i do? 回答1: i think you should use: var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("TokenAuthentication:SecretKey"

Web API returns escaped JSON

随声附和 提交于 2019-12-12 13:29:38
问题 I have a POST method in a .NET core 2.0 web API project that needs to return a JSON (using newtonsoft). I have the following code at the end of the method: ObjectResult objRes = new ObjectResult(JsonConvert.SerializeObject(result, settings)); objRes.ContentTypes.Add(new MediaTypeHeaderValue("application/json")); return objRes When I test this using Postman I get a result like: "{\"name\":\"test\",\"value\":\"test\"}" As you can see, the JSON is still escaped in postman. When I test the exact