asp.net-core-webapi

Increase timeout in Angular 2+ and ASP.NET Core WebAPI application

痴心易碎 提交于 2020-01-05 04:32:05
问题 In my Angular 2+ / ASP.NET Core MVC WebAPI application I have a long running API-call from the client UI to the server. The request times out after 30 seconds. I would like to define the timeout for this specific API call either client- or server-side. I have only found ways to configure the server timeout globally, which is not what I want, as the 30 second timeout is fine for other calls. I've also found solutions to decrease the timeout client side by piping RxJS's timeout operator.

HttpContext.Request is blank for a middleware running on AWS API Gateway

試著忘記壹切 提交于 2020-01-05 04:18:10
问题 I have a .Net Core webapi that i have deployed on the AWS API Gateway. I created a middleware to process all incoming requests and outgoing responses. That middleware works perfectly fine on any local machine, which means, before http request hits my api controller, it goes through that middleware and being processed there correctly, but when it is deployed to AWS API Gateway, context.Request is always blank... Here is how the middleware is implemented public class RequestLoggingMiddleware {

How to pass a service from .net core di container to a new object created with automapper

佐手、 提交于 2020-01-05 04:16:30
问题 I'm facing a scenario where I need to inject a service from asp.net core DI container to the constructor of an object created using automapper. I don't know if this is the best practice but let me explain what I'm trying to accomplish. I've an asp.net core mvc controller that receives a model parameter, just a POCO, that model needs to be converted into a ViewModel class that contains some business logic, data access etc, in that class object I want to get some info from the injected service,

How to forward HTTP response to client

柔情痞子 提交于 2020-01-04 05:36:44
问题 I have a client (Xamarin) and two Web API servers, A and B. The client makes a request to A which uses the request parameters to make another request to B. How do I return the response that A receives from B to the client such that B's use of C is transparent to the client. For example, if I make a request from A to B using HttpClient how do I forward the HttpResponseMessage to the client in a controller's action? 回答1: Look at the Microsoft ASP.NET Core Proxy repository for a good example of

Azure AD OAuth client credentials grant flow with Web API AuthorizeAttribute Roles

时光毁灭记忆、已成空白 提交于 2020-01-04 03:18:23
问题 Given We have a .NET Web API service. It secures access to controllers and actions using the AuthorizeAttribute with Roles . For example: [Authorize(Roles = "Reader,Requester,Editor,Approver,Administrator")] There is an App Registration within Azure Active Directory for this application. It uses OAuth for user impersonation, and users are authenticating correctly. There are many tutorials available on getting to this point. Intent We wish to have an unattended scheduled process (a script)

POST actions in [ApiController] in ASP.NET Core 2.1

荒凉一梦 提交于 2020-01-03 17:24:09
问题 I have the following ASP.NET Core 2.1 Api controller: [Route("api/[controller]")] [ApiController] public class ImagesController : ControllerBase { [HttpPost("[action]")] public async Task<IActionResult> Upload([FromForm]ICollection<IFormFile> files) { ... } [HttpGet("thumbnails")] public async Task<IActionResult> GetThumbNails() { ... } Both the GET and POST actions worked with Postman. However, the POST action would not work with the UI: the action would always receive a files parameter

How to create two type of users with identity and .net core 2

两盒软妹~` 提交于 2020-01-03 03:23:33
问题 I start to develop an web application with .net core 2 and web service.. when a user registers on the site, he can choose whether he is a company or a simple user, so I store the data in a specific table but the login data are stored in AspNetUsers. How can i handle it with Identity in .net core? 回答1: Simply inherit from ApplicationUser , i.e.: public class CompanyUser : ApplicationUser {} public class SimpleUser : ApplicationUser {} By default, EF will implement inheritance via STI (single

How to inject HttpHeader value in controller?

こ雲淡風輕ζ 提交于 2020-01-02 03:33:06
问题 I have Web API developed using ASP.NET Core API. Every incoming request has a custom header value inserted. eg x-correlationid . The controller use this value for logging and tracing the request. Currently I'm reading the value in each controller as below [Route("api/[controller]")] public class DocumentController : Controller { private ILogger<TransformController> _logger; private string _correlationid = null; public DocumentController(ILogger<DocumentController > logger) { _logger = logger;

FluentValidation.AspNetCore is not working in Class Library

寵の児 提交于 2020-01-01 12:04:08
问题 I am using library "FluentValidation.AspNetCore": "6.4.0-beta3" in .netcore WebApi in a project. You can see the project structure below. Library is working fine if i place the CurrencyDTO.cs code in section 2 (Project FH.WebAPI) and if the same code placed in section 1 (Class Library DTO) its not working. And requirement is that i have to place code in Class library FH.Common . Is there any work around.I have search but didn't find any thing Project Structure CurrencyDTO.cs [Validator(typeof

Get image from wwwroot/images in ASP.Net Core

拈花ヽ惹草 提交于 2020-01-01 06:36:27
问题 I have an image in wwwroot/img folder and want to use it in my server side code. How can I get the path to this image in code? The code is like this: Graphics graphics = Graphics.FromImage(path) 回答1: string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images"}"; 回答2: It would be cleaner to inject an IHostingEnvironment and then either use its WebRootPath or WebRootFileProvider properties. For example in a controller: private readonly IHostingEnvironment env; public HomeController