DOTNET -Kernanwendung, die 500 interne Serverreaktion nach dem Hosting auf IIS neu beauftragtC#

Ein Treffpunkt für C#-Programmierer
Guest
 DOTNET -Kernanwendung, die 500 interne Serverreaktion nach dem Hosting auf IIS neu beauftragt

Post by Guest »

Ich habe den REST -API -Dienst im Dotnet Core erstellt. Die Anwendungsendpunkte funktionieren einwandfrei, wenn ich aus dem Code ausgeführt werde, aber nachdem ich ihn auf dem IIS -Server veröffentlicht habe, wenn ich versuche, darauf zuzugreifen, gibt es mir die folgende Fehlerantwort < /p>

Code: Select all

{
"StatusCode": 500,
"Message": "An unexpected error occurred. Please try again later.",
"Details": "The exception handler configured on ExceptionHandlerOptions produced a 404 status response. This InvalidOperationException containing the original exception was thrown since this is often due to a misconfigured ExceptionHandlingPath. If the exception handler is expected to return 404 status responses then set AllowStatusCode404Response to true."
}
< /code>
Ich habe nach zu vielen Lösungen gesucht, aber für mich funktioniert nichts.
Ich habe einfach eine Website in IIS erstellt. Seine Anwendungspool hinzugefügt, binden Sie ihn richtig, aber immer noch kein Glück.public class ExceptionHandlingMiddleware
{
private readonly RequestDelegate _next;

public ExceptionHandlingMiddleware(RequestDelegate next)
{
_next = next;
}

public async Task InvokeAsync(HttpContext context)
{
try
{
await _next(context); // Call the next middleware
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex);
}
}

private static Task HandleExceptionAsync(HttpContext context, Exception exception)
{
// Log the exception (optional)
Console.WriteLine($"Exception: {exception.Message}");

var response = new
{
StatusCode = (int)HttpStatusCode.InternalServerError,
Message = "An unexpected error occurred. Please try again later.",
Details = exception.Message // Include more details for development environment
};

context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return context.Response.WriteAsync(JsonSerializer.Serialize(response));
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post