Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
77 views

Cannot read request body in HttpRequestTelemetryInitializer

I want to read the Body of incoming requests with the help of my HttpRequestTelemetryInitializer class. Although my GetRequestHeader method works successfully, I get the following error on the var ...
Mehmet Serkan Ekinci's user avatar
0 votes
0 answers
67 views

Global error handler for ASP.NET Core application

I am trying to configure a global error handler for my web app. Configuration In the Startup.cs Configure method: if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app....
Ryan's user avatar
  • 672
0 votes
1 answer
41 views

app.UseStatusCodePagesWithReExecute Does Not Seem to Execute Pipeline Again

In my .NET 7 web site, I've set up the processing pipeline to use UseStatusCodePagesWithReExecute but with a registered middleware in the pipeline returns 404, it correctly returns the 404.cshtml page,...
Terry's user avatar
  • 1,920
-1 votes
1 answer
53 views

If Migration is not sent to the database, UseExceptionHandler Middleware will not work. Why?

I added a new property in a entity class. I didn't create migration. After that, I tried to use UseExceptionHandler middleware. It successfully triggered error action method but the view didn't appear....
Onur's user avatar
  • 1
0 votes
1 answer
191 views

Best Practices for using middleware in ASP.NET Core Web API for exception handling, authentication, and error logging

I'm working on an ASP.NET Core Web API project and I am trying to implement some global functionalities using middleware. Specifically, I want to handle the following: Global exception handling: ...
Abdullah Sameer's user avatar
0 votes
1 answer
159 views

ASP.NET Core is logging "request unhandled" even though it is handled by my middleware

I have some middleware which sets a response status code, content type and content (with SendFileAsync) yet the log file contains a debug message from Microsoft.AspNetCore.Hosting.Diagnostics saying &...
Ian Horwill's user avatar
  • 3,017
0 votes
1 answer
112 views

Access response body in middleware unit test

I have a .net middleware that modifies the response and I'm trying to unit test it. I am able to successfully assert the status code and content type are correct, but when I attempt to assert the ...
tariq's user avatar
  • 109
0 votes
0 answers
80 views

Using ASP.NET Core 8 Web API project : I am trying to access controller and its attributes from middleware

In my ASP.NET Core 8 Web API based project, I have a middleware which is being executed for every request. I want to avoid this situation and want it to only execute for those API controllers which ...
Shahzad's user avatar
-2 votes
1 answer
90 views

Cannot access a disposed object in Entity Framework

I am creating a middleware to store all incoming API request and response body along with some other data, I am using Entity Framework as my ORM. It's working well, but in some request and response ...
Shakeeb Kp's user avatar
0 votes
0 answers
60 views

How to create middleware API in .NET Core

I need to write a middleware micro service API from another website which is SSL secured; I need to load the certificate and wait for any post calls on that url and catch the data in my end. I have ...
Nikola's user avatar
  • 1
0 votes
1 answer
232 views

Access denied when adding rule to Windows firewall (INetFwPolicy2) with C# from Core Middleware program

I'm trying to add a rule to Windows firewall in .Net Core Middleware (httpHandler) written in C# . The code looks like this: INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type....
Velocedge's user avatar
  • 1,393
2 votes
1 answer
342 views

Modifying `Request.Path` via middleware in an ASP.NET Core Web API project does not change the controller/action used

I have a small sandbox application based on the ASP.NET Core Web API template where I am attempting to modify the controller/action to be used based on a custom header and to facilitate this I am ...
Gabriel Read's user avatar
-1 votes
2 answers
524 views

Why a middleware does not get executed if applied after app.UseEndpoints() in ASP.NET Core Web APIs

I am trying to create a middleware that should execute after the execution of endpoint. But when I add middleware in after the app.UseEndPoints(), it never gets invoked, however it is invoked if ...
rf_khan's user avatar
0 votes
0 answers
116 views

C# Asp.Net Core Middleware - Page Loading Time

I have implemented a middleware class that determines the elapsed time that a page took to load. public sealed class PageLoadTimeMiddleware { private readonly RequestDelegate _next; ...
Goober's user avatar
  • 13.4k
0 votes
1 answer
109 views

Create Ocelot middleware in c#

Net core. I am trying to implement Authorization in Ocelot gateway but due to some oprn issues at ocelot side i am looking at alternatives mentioned at https://github.com/ThreeMammals/Ocelot/issues/...
Niranjan's user avatar
  • 281
0 votes
0 answers
69 views

ASP.NET Core Middleware - redirect happens before code for changing headers is executed

I have written a middleware that supposed to cache a specific endpoint redirect (302) and add parameters to it's query string. This is my middleware code: public class ...
developer82's user avatar
  • 13.6k
0 votes
1 answer
586 views

Redirect to login from .NET Core auth middleware

I have an ASP.NET Core 8 MVC app, and I'm using auth middleware to authenticate and ensure that an access token (JWT) resides in the cookies. Working to make sure that when an action with an [...
coach_rob's user avatar
  • 901
0 votes
2 answers
150 views

Inline middleware doesn't work in Asp.Net WebApi template project

I created a new Asp.Net WebApi project just to experiment, and I added a new inline middleware as in the documentation. The application starts, but when calling the action from Swagger I get a result ...
Daniele Armanasco's user avatar
1 vote
1 answer
502 views

Prometheus not Scraping Custom Metrics (prometheus_demo_request_total) from ASP.NET Core Application with OpenTelemetry

I have implemented a custom middleware in my ASP.NET Core application to log HTTP request metrics using Prometheus. I implemented the middleware using the link. However, despite the middleware being ...
Ammar's user avatar
  • 43
0 votes
0 answers
215 views

Matching and Rebuilding URL Routes in ASP.NET Core

I'm working on an ASP.NET Core application where I have a default route template, for example: ~/api/{area}/[controller]/{action?}/{id?}. My goal is to match incoming URLs with other route templates ...
Emre Kabaoglu's user avatar
0 votes
2 answers
144 views

Returning multiple implementations of same interface from Abstract Factory with ASP.NET Core

I want to make multiple implementations of a specific interface accessible through an Abstract Factory in .NET Core. Based on a supplied enum the correct implementation should be returned. This is my ...
Engin Şengül's user avatar
0 votes
1 answer
97 views

Show 404 status and page-not-found View without actually redirecting to pagenotfound Nopcommerce 4.5

Using Nopcommerce V.4.5 Whenever there is a 404 error it redirect to /pagenotfound. I am trying for it to show the same View on the original URL that was 404. So far: I have added a custom middleware ...
confusedMind's user avatar
  • 2,633
0 votes
0 answers
61 views

How to inject a script in html pages without touching the application code in ASP.NET Core

I want to inject some Javascript code (which tracks total requests made from browser) in html responses in my ASP.NET Core application. I know that we can use middleware to manipulate the responses in ...
Zader's user avatar
  • 77
0 votes
1 answer
69 views

RequestDelegate as discard parameter in custom middleware class

I saw the following code: class ReaderMiddleware { IReader reader; public ReaderMiddleware(RequestDelegate _, IReader reader) => this.reader = reader; public async Task ...
Anthony Voronkov's user avatar
3 votes
1 answer
277 views

ASP.NET C# WebApp passing named parameters to custom middleware using app.UseMiddleware

C# aspnet webapp, I have the following constructor in my middleware: public MiddlewareCustomRuntimeExceptionHandler (RequestDelegate next, ILogger<MiddlewareCustomRuntimeExceptionHandler> ...
Tapani Talvitie's user avatar
0 votes
0 answers
42 views

An .NET API; how to respond to large multi-form request without closing connection?

Consider this client request: var content = new MultipartFormDataContent(); var stream = new FileStream("c:\10GB.zip", FileMode.Open, FileAccess.Read); content.Add(new StreamContent(stream), ...
Jonas Rembratt's user avatar
1 vote
1 answer
617 views

ASP.NET Core - Can UseSession() be used before UseAuthentication() and UseAuthorization()?

I'm working on an ASP.NET code base that uses sessions, authentication, and authorization. They are initialized in the following order: app.UseSession(); app.UseAuthentication(); app.UseAuthorization()...
micka190's user avatar
  • 912
0 votes
0 answers
113 views

Middleware Or Filter

I have a scenario where I want to check a feature flag per request. The way I have implemented this so far is I use middleware.. public class SalesFeatureMiddleware { private readonly ...
Dr Schizo's user avatar
  • 4,302
0 votes
0 answers
23 views

how to log model custom error msg in sql database

Build a Web API named, "DeviceManager" a. Build a model for below details and continue from model[model first] Device model: i. DeviceId - with regular expression "[A-Z]{3}[0-9]{7}"...
BR Naveen's user avatar
0 votes
1 answer
260 views

ASP.NET Core: Cancelled tasks get stuck in IIS Worker Process, causing application to be un-responsive to the users

At the time of high user traffic, the server struggles to keep up with the user requests, which causes the users to refresh the page one or more time. This causes the cancelled tasks to pile up in the ...
Muhammad Usama's user avatar
0 votes
1 answer
646 views

Why is my ASP.NET Core middleware pipeline short-circuit code returning an empty response?

I have an ASP.NET Core web application in which I have a pipeline of several custom middleware functions. I'm trying to add a new one to the beginning of the pipeline that short-circuits the rest of ...
Ryan's user avatar
  • 7,895
2 votes
2 answers
2k views

Error when modifying response headers in middleware

I'm trying to modify the response headers in some middleware after it has finished in the controller, but I'm getting an error message: System.InvalidOperationException: Headers are read-only, ...
Q-bertsuit's user avatar
  • 3,407
0 votes
1 answer
513 views

Is there a way to stop middleware propagation in OnAuthenticationFailed event in ASP.NET Core?

I use the event OnAuthenticationFailed in JWTBearer only to handle the response when the token expires. Here's the code: services.AddAuthentication(x => { x.DefaultAuthenticateScheme = ...
Maskliv's user avatar
0 votes
1 answer
532 views

How to run a middleware first in a pipeline but with endpoint metadata?

I need to filter some of our API actions to work only from local host. Seems there are a few methods to accomplish this: setup CORS; Add an Authorization filter or an Action filter; Add a middleware ...
Kasbolat Kumakhov's user avatar
1 vote
1 answer
99 views

strange behaviour with exception handling

i have a dotnet core 6 api with a very strange behaviour in exception handling there's an exception middleware that should handle all exception in api calls (which is correctly instantiated in app ...
p.desterlich's user avatar
1 vote
1 answer
338 views

Using different loggers or logging configurations in .NET 7 API

I have a React app that uses a .NET 7 API. We are using Graylog for logging. The idea is to provide an API endpoint for the react app to POST its error logs. I want to use a different log source if ...
Junaid's user avatar
  • 1,010
0 votes
1 answer
362 views

Handle outbound proxy in .net core

I am migrating the asp.net web application to asp.net core 6.0. For handling inbound proxies i have followed the following Microsoft link; https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/...
user1263981's user avatar
  • 3,107
0 votes
1 answer
453 views

Rewriting ASP.NET Core response duplicates the content instead of replacing the original stream

I have an ASP.NET Core application with a custom middleware designed to replace some external CDN links. The middleware correctly updates the response body with the new data, but keeps appending it to ...
Dezzamondo's user avatar
  • 2,278
0 votes
1 answer
1k views

Statements after await next(context) is not executed in ASP.NET Core middleware

I have created a custom middleware and added a statements before and after the await next(context) method call. If there is no middleware after my custom middleware, then the statements after next(...
Ambareesh's user avatar
0 votes
1 answer
420 views

How can I set a default header for all the HTTP requests using DelegatingHandler middlewhare?

I use a middleware for an HttpClient. I use one instance of HttpClient as a singleton (we don't use DI, otherwise an HttpClientFactory would be a better option). My question: Is it possible to set a ...
arsenii41.2hz's user avatar
0 votes
0 answers
210 views

ASP.NET Core failed requests is getting executed multiple times

I have an ASP.NET Core 6.0 Web API. One of the middleware catches an exception and translates it to a user-friendly error message as response. This is existing web API and multiple middleware are ...
user9297554's user avatar
0 votes
1 answer
338 views

How to fix the problems in my global error handling page?

I am working on an ASP.NET Core 6 MVC project and trying to implement global error handling for web pages. Currently, the code is local on my laptop with Windows 11, Visual Studio 2022 and using ...
bedrock's user avatar
  • 576
0 votes
1 answer
94 views

ASP.NET Core - Middleware Reordering in Startup class

I have used two Map methods one after other in Startup class in a demo ASP.NET Core 5.0 Empty project. I know that Map method is used to branch the middleware pipeline. As per the pathMatch string, ...
AppliedK's user avatar
0 votes
1 answer
858 views

Integrate Prometheus scraping endpoint with ASP.NET Core pipeline

We're trying to integrate the prometheus scrape endpoint with an existing ASP.NET Core site which hosts a Web API. Here's how the middleware is configured (showing only the important part): app....
Luis Abreu's user avatar
  • 4,334
3 votes
0 answers
457 views

.NET 6 Why does fail to intercept the response body in middleware when a request is canceled?

I wrote a middleware in .NET 6 Web API to handle some response body processing, but I noticed that if the request is canceled before I finish processing inside, I will receive an empty response body ...
Kitty Chen's user avatar
0 votes
0 answers
84 views

Getting No Response When Using GetEndPoint Method and Getting An 405 Error when not using GetEndPoint Method?

Code 1: var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); app.UseRouting(); app.Use(async (context, next) => { var endPoint = context.GetEndpoint(); if (endPoint != null)...
Hamza Bilal's user avatar
0 votes
1 answer
288 views

Use UseStatusCodePagesWithReExecute with UseStaticFiles when method = POST

I'm using UseStatusCodePagesWithReExecute with UseStaticFiles to show an error page. app.UseStatusCodePagesWithReExecute("/Errors/{0}.html"); app.UseStaticFiles(); This works fine for GET ...
Bouke's user avatar
  • 12k
1 vote
1 answer
822 views

Session In Razor View

Does anyone know how to set the Session in Razor View in ASP.NET Core? And how to get that value in a controller or anywhere else? // set the session in controller like that: HttpContext.Session....
Web_Dev Haseeb's user avatar
0 votes
0 answers
293 views

Exception handling custom middleware dotnet core

I am facing very strange issue where in, i am using a custom middleware to validate to validate the headers being passed to my api and then executes the constructor of a class with a scoped lifetime. ...
aditya's user avatar
  • 342
3 votes
1 answer
908 views

Middleware called twice

I implemented a middleware en .net core to read the request and verify if the attributeody of name is contained 2 times in the body of the request. I am getting grazy, I cannot figure out how is it ...
Kenzo_Gilead's user avatar
  • 2,421

1
2 3 4 5
9