416 questions
0
votes
1
answer
270
views
Difference between RequestDelegate and Middleware in ASP.NET Core?
I was recently in a technical discussion with a senior developer and was asked:
What is the difference between RequestDelegate and Middleware in ASP.NET Core?
I have already visited the following ...
0
votes
1
answer
179
views
'InvalidOperationException: Unable to resolve service for type' exception thrown while trying to implement exception handling Middleware
I am trying to implement a custom middleware to globally handle exceptions in my ASP.NET Core Web API project. My .NET Core version is 9.0. I created a custom class by extending from IMiddleware.
My ...
0
votes
1
answer
217
views
Durable Function with Global Exception Handler
We have a Durable Function with multiple orchestrators and activities. We would like to use a middleware as global exception handler instead of handling it in every orchestrator/activity. We can catch ...
0
votes
1
answer
491
views
Single app.UseWhen vs multiple app.UseWhen
In ASP .NET Core app want to make one of my controllers sessionless. So I do the following:
app.UseWhen(
context => context.GetRouteValue("controller") is not "SomeValue",
app =&...
0
votes
1
answer
697
views
ASP.NET Core 8 - UseWhen and pass HttpContext as parameter
I needed a custom file provider, and to access a request's HttpContext, I found a solution using IHttpContextAccessor:
app.UseWhen(ctx => ctx.Request.Path.StartsWithSegments("/res", ...
0
votes
1
answer
206
views
UseStaticFiles, set folder dynamically based on host
I need to allow for individual hosts to have their own folder serving static files.
Started out doing like this:
var hosts = cfg.GetSection("AppSettings:AvailableHosts").Get<string[]>()...
2
votes
1
answer
138
views
ASP.NET Core - CORS error when posting the request despite allowing all origins
Whenever I send a POST request to my server from a frontend webpage I've made, the DevTools console throws the error below:
Access to fetch at 'http://127.0.0.1:5000/CreateBooking' from origin 'http:/...
1
vote
1
answer
173
views
Object as a Scoped Service, With Values being Set in Middleware, Sometimes Remains Null
I use the following to create an instance of a class for storing user information during the request:
services.AddScoped<IUserSettings, UserSettings>();
Then I use middleware to set the values ...
0
votes
1
answer
113
views
Process one request and enqueue other requests using Semaphore in Middleware
I am using semaphore to handle one request at a time and enqueue other request and process in sequence. But when I run the code it run first request and drop other request. What I am doing wrong here?...
0
votes
1
answer
105
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 ...
0
votes
0
answers
77
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....
0
votes
1
answer
120
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,...
-1
votes
1
answer
65
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....
0
votes
1
answer
1k
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: ...
0
votes
1
answer
577
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 &...