Developer forum

Forum » Dynamicweb 10 » Exception handling

Exception handling

Karol Barkowski
Reply

Hi,

I was trying to understand how the "Debugging" section and it's corresponding exception settings work. Those can be found on the Setting -> Web & http -> Security page.
Now, I was hoping that those setting will let me handle exceptions in my own way and stop DW from showing the server stack trace and template source code to users. So I checked those three options as shown below, I added my own middleware responsible for dealing with any uncaught exception and I started testing. And... nothing seems to be changing. I recycled app pool after each and every change, I tried different combinations of those settings below but no matter what I do, my middleware never gets called and I can still see the stack trace and template source code shown right to the user.
What exactly this section is doing? 


Replies

 
Karol Barkowski
Reply

Oh, and side note - if you go to "Setting -> Web & http -> Security" and hit "Save", it shows model validation errors so it looks like all the default form values are ignored and you need to explicitly type all those deafilt values in order to be able to save anything.
Would be nice to have that bug fixed, if possible.

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Karol

The feature is described here: https://doc.dynamicweb.dev/manual/dynamicweb10/settings/system/webhttp/security.html#debugging

You do not show any middleware code - maybe tell what the code is and how you install it?

We will bug the validation thing - thanks for observing!

BR Nicolai

 
Karol Barkowski
Reply

Hi,

my middleware currently has no logic so I don't think it has anything to do with the problem, it looks like that:

    public class ExceptionHandlingMiddleware(RequestDelegate next)
    {
        private readonly RequestDelegate _next = next;

        public async Task InvokeAsync(HttpContext context)
        {
            try
            {
                //this get's called
                await _next(context);
            }
            catch
            {
                //this never gets called
                await context.Response.WriteAsync("Error");
            }
        }
    }

Which then is registered in Program.cs with a call to "app.UseMiddleware<ExceptionHandlingMiddleware>();"
Pretty standard stuff in .net core. It works out  of the box in any other project.

But the problem is that no matter the exception settings are in that admin section, my "catch" statement will never be called. Apparently all the exceptions are "swallowed" by DW code and currently it is not possible to stop it from showing stack trace and template code on screen (which on it's own is a huge problem).

What I need to achieve is this - whenever an unhadled exception happens, I need to handle that situation with my code. I don't want any of those built in "handlers" as they expose to the UI information that should never, under any circumstances be shown there. So I need to shut them off completely and handle exception properly.

Is it possible?

 

 

 

You must be logged in to post in the forum