asp.net-core-webapi

Use One Identity for WebAPI and Asp.Net Core In different projects

六月ゝ 毕业季﹏ 提交于 2021-01-28 03:25:49
问题 I have a solution that contains 2 dot net core projects : Web API Web Application(MVC) The web application is a web API consumer. My web application controller will use httpclient for getting data and I use razor for the client (no Javascript library such as Angular). I want to use Microsoft identity for authentication and recently I have read about JWT . In which project should I add Microsoft Identity? (Because we need authentication for building a token in JWT ) If I must add it in the Web

Can't bind params using [FromQuery] ASP Net Core 2 API

青春壹個敷衍的年華 提交于 2021-01-27 18:36:14
问题 I'm new in ASP Net Core 2, I want to bind different parameters that come from URL query string to action parameters in my action: [HttpGet("{page}&{pageSize}&{predicate}", Name = "GetBuildingsBySearchCriteria")] public IActionResult GetBuildingsBySearchCriteria([FromHeader] string idUser, [FromQuery]int page, [FromQuery]int pageSize, [FromQuery]string predicate) { .... } When I test my action using postman, I set the idUser in header and other parameters in URL, example: http://localhost

How to upload image from React to ASP.NET Core Web API?

时光怂恿深爱的人放手 提交于 2021-01-27 16:02:12
问题 I have Web API controller in mt server side [HttpPost("CreateImage")] public void CreateImage([FromBody] ImageDTO img) { Image image = new Image { FileName = img.FileName }; byte[] imageData = null; using (var binaryReader = new BinaryReader(img.Image.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)img.Image.Length); } image.Picture = imageData; imageRepo.Create(image); } Where ImageDTO is public class ImageDTO { public string FileName { get; set; } public IFormFile Image { get;

Avoid bind any number to bool property

試著忘記壹切 提交于 2021-01-27 06:03:40
问题 I have simple ASP.NET Core WebApi with model public class Model { public bool? Value {get; set;} } and endpoint [HttpPost] public async Task<IActionResult> Create([FromBody] Model model) When I make a POST request with body { "Value" : 7676 } or { "Value" : 2955454545645645645645645645654534534540 } then model.Value == true How to avoid this? I need some error in this case, because 7676 is not the Boolean value. I found this question and this, but solution is not fit for me, because I have a

String Trim Model Binder in ASP .NET Core 2

若如初见. 提交于 2021-01-23 20:23:49
问题 I'm working on a .NET Core 2 API project and have been trying to implement a universal string trim model binder that would trim all string values of provided request parameters and field values. So far I have had mixed results and am struggling to find working example that would point me in the right direction. I've been trying to implement the same model binder as posted by Vikash Kumar. This model binder works fine for all string values that are passed into controller actions via direct

String Trim Model Binder in ASP .NET Core 2

[亡魂溺海] 提交于 2021-01-23 20:23:20
问题 I'm working on a .NET Core 2 API project and have been trying to implement a universal string trim model binder that would trim all string values of provided request parameters and field values. So far I have had mixed results and am struggling to find working example that would point me in the right direction. I've been trying to implement the same model binder as posted by Vikash Kumar. This model binder works fine for all string values that are passed into controller actions via direct

String Trim Model Binder in ASP .NET Core 2

不打扰是莪最后的温柔 提交于 2021-01-23 20:21:53
问题 I'm working on a .NET Core 2 API project and have been trying to implement a universal string trim model binder that would trim all string values of provided request parameters and field values. So far I have had mixed results and am struggling to find working example that would point me in the right direction. I've been trying to implement the same model binder as posted by Vikash Kumar. This model binder works fine for all string values that are passed into controller actions via direct

String Trim Model Binder in ASP .NET Core 2

大憨熊 提交于 2021-01-23 20:21:47
问题 I'm working on a .NET Core 2 API project and have been trying to implement a universal string trim model binder that would trim all string values of provided request parameters and field values. So far I have had mixed results and am struggling to find working example that would point me in the right direction. I've been trying to implement the same model binder as posted by Vikash Kumar. This model binder works fine for all string values that are passed into controller actions via direct

String Trim Model Binder in ASP .NET Core 2

江枫思渺然 提交于 2021-01-23 20:19:28
问题 I'm working on a .NET Core 2 API project and have been trying to implement a universal string trim model binder that would trim all string values of provided request parameters and field values. So far I have had mixed results and am struggling to find working example that would point me in the right direction. I've been trying to implement the same model binder as posted by Vikash Kumar. This model binder works fine for all string values that are passed into controller actions via direct

How to authenticate a user when consuming MassTransit messages in Asp.Net Core Web API?

匆匆过客 提交于 2021-01-21 05:07:12
问题 I have several Asp.Net Core Web APIs that use Bearer authentication and IdentityServer4.AccessTokenValidation middleware to introspect tokens, authenticate the user and create claims. This works fine for HTTP requests. I am in the process of configuring these APIs to also be MassTransit endpoints (for both Publishing and Consuming messages) using RabbitMQ as transport. I followed the instructions here for adding MassTransit to the API and for setting up message consumers. A typical workflow