ASP.NET CORE 6 Web -API - Elmah behandelt 404 Fehler, aber nicht auf meine Ausnahmefilter. Daher kann ich mich nicht daf

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: ASP.NET CORE 6 Web -API - Elmah behandelt 404 Fehler, aber nicht auf meine Ausnahmefilter. Daher kann ich mich nicht daf

by Anonymous » 08 Apr 2025, 12:05

Ich habe eine ASP.NET Core 6 -Web -API. Es ist öffentlich. Ich habe das eingerichtet: < /p>

Code: Select all

public void ConfigureServices( IServiceCollection services )
{
services.AddMvc(options => options.Filters.Add(typeof(ExceptionFilter)));
// ...
}
In der Methode konfigurieren nenne ich Folgendes:
if (GetUseErrorEmailVar())
{
app.UseExceptionHandler(appException =>
{
appException.Run(async context =>
{
var exceptionFeature = context.Features.Get();

if ( exceptionFeature?.Error is FileNotFoundException )
{
await context.Response.WriteAsync(" The file was not found.");
}

if (exceptionFeature?.Path == "/")
{
await context.Response.WriteAsync(" Page: Home.");
}

if (exceptionFeature.Error is ApiErrorException exception)
{
await context.Response.WriteAsync(JsonConvert.SerializeObject(new BaseReturnDataObject
{
ErrorType = exception.GetType().ToString(),
ErrorMsg = exception.Message
}
)
);
}
////else if (exceptionFeature.Error is ApiLoginErrorException exception2)
////{
//// // Debug instead of error, because SMTP appender makes a duplicate email (actually 3) - EWB
//// log.LogDebug("Startup::Configure(...):: Global exception handler ; LOGIN ex:" + exceptionFeature.Error.ToStringNullSafe());
////}
////else// everything else -EWB
////{
//// // Debug instead of error, because SMTP appender makes a duplicate email (actually 3) - EWB
//// log.LogDebug("Startup::Configure(...):: Global exception handler ; ERROR ex:"+ exceptionFeature.Error.ToStringNullSafe());
////
//// exceptionFeature.Error.Data["handled"] = true;
////}
});
});
}
app.UseElmah();// must be after all other handlers and middleware for errors. -EWB
< /code>
Aber weder dieser Ausnahme -Handler Lambda noch mein explizite Ausnahmebehandler werden aufgerufen, sodass ich entscheiden kann, ob es die Nachricht unterdrückt oder nicht, wenn es sich um 404 handelt. Wie Sachen, von denen ich noch nie gehört habe ... Ich gehe davon aus, dass sie von späteren Versionen der Web -API stammen. Ich bin auf .net 6.

Top