asp.net-core-middleware

ImageSharp.Web - resize image by querystring in Asp.Net Core 3.1

╄→尐↘猪︶ㄣ 提交于 2021-02-11 14:48:14
问题 I am trying to use ImageSharp.Web to resize images through querystring parameters eg: http://localhost:5001/content/photo/img.jpg?width=800&height=600 I created a new MVC Asp.Net Core 3.1 project, installed the packages and followed the Documentation I tried the minimum configuration described and several variations, but it seems that the middleware is not intercepting the image request. I always get the original image and no error is triggered. Am I missing something? What would be the

StatusCodePagesMiddleware doesn't intercept exceptions?

天涯浪子 提交于 2021-01-28 06:11:50
问题 For example, in the Index page: public ActionResult OnGet() { //return StatusCode(500); throw new Exception(); } My Startup configuration: public void Configure(IApplicationBuilder app) { //app.UseStatusCodePagesWithReExecute("/Error", "?statusCode={0}"); app.UseStatusCodePages(); app.UseStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); } When the Index.OnGet() gets executed and throws the exception, the default 500 page of the browser is shown

JToken.WriteToAsync does not write to JsonWriter

拟墨画扇 提交于 2021-01-27 12:54:23
问题 I'm trying to create a middleware that changes the request in a certain way. I am able to read it and change the content but I cannot figure out how to correctly setup the stream writers to create a new body. When I call normalized.WriteToAsync(jsonWriter) the MemoryStream remains empty and consequently I receive the A non-empty request body is required. exception. What am I missing here? This is what I have so far: public async Task Invoke(HttpContext context) { if (context.Request

How to handle dynamic error pages in .net MVC Core?

断了今生、忘了曾经 提交于 2020-12-05 04:58:27
问题 Currently I have app.UseExceptionHandler("/Home/Error"); I want to make the path relative to the original path. For example if Tenant1/PageThatThrowsError then app.UseExceptionHandler("Tenant1/Home/Error"); but if Tenant2/PageThatThrowsError then app.UseExceptionHandler("Tenant2/Home/Error"); I thought I would be able to do app.UseExceptionHandler( new ExceptionHandlerOptions { ExceptionHandler = async (ctx) => { //logic that extracts tenant ctx.Request.Path = new PathString(Invariant($"

How to handle dynamic error pages in .net MVC Core?

偶尔善良 提交于 2020-12-05 04:57:32
问题 Currently I have app.UseExceptionHandler("/Home/Error"); I want to make the path relative to the original path. For example if Tenant1/PageThatThrowsError then app.UseExceptionHandler("Tenant1/Home/Error"); but if Tenant2/PageThatThrowsError then app.UseExceptionHandler("Tenant2/Home/Error"); I thought I would be able to do app.UseExceptionHandler( new ExceptionHandlerOptions { ExceptionHandler = async (ctx) => { //logic that extracts tenant ctx.Request.Path = new PathString(Invariant($"

How to handle dynamic error pages in .net MVC Core?

送分小仙女□ 提交于 2020-12-05 04:57:06
问题 Currently I have app.UseExceptionHandler("/Home/Error"); I want to make the path relative to the original path. For example if Tenant1/PageThatThrowsError then app.UseExceptionHandler("Tenant1/Home/Error"); but if Tenant2/PageThatThrowsError then app.UseExceptionHandler("Tenant2/Home/Error"); I thought I would be able to do app.UseExceptionHandler( new ExceptionHandlerOptions { ExceptionHandler = async (ctx) => { //logic that extracts tenant ctx.Request.Path = new PathString(Invariant($"

Serilog logging web-api methods, adding context properties inside middleware

不羁岁月 提交于 2020-12-03 07:37:16
问题 I've been struggling to log response body payload data with serilog, logging from middleware. I'm working on WEB API Core application, with swagger added to endpoints, and my goal is to log every endpoint call to a .json file with serilog (both request and response data). For GET requests, body of the response should be logged (added to serilog context as a property), and for POST requests, both body of request and response should be logged. I have created middleware and managed to properly

Serilog logging web-api methods, adding context properties inside middleware

好久不见. 提交于 2020-12-03 07:34:21
问题 I've been struggling to log response body payload data with serilog, logging from middleware. I'm working on WEB API Core application, with swagger added to endpoints, and my goal is to log every endpoint call to a .json file with serilog (both request and response data). For GET requests, body of the response should be logged (added to serilog context as a property), and for POST requests, both body of request and response should be logged. I have created middleware and managed to properly