question

khamissafy-6344 avatar image
0 Votes"
khamissafy-6344 asked DuaneArnold-0443 edited

i'am getting status 500 in my asp net core code

My ajax Code

101400-1-ajax.png



My Action Method

101424-1-code1.png


101443-1-code2.png101438-1-code3.png101425-1-codeconsole.png101444-1-data.png








My Console Response
Notice** My log didn't Printed


And The data retuened to the ajax

dotnet-aspnet-core-mvc
1-ajax.png (36.1 KiB)
1-code1.png (20.8 KiB)
1-code2.png (21.1 KiB)
1-code3.png (26.6 KiB)
1-codeconsole.png (11.3 KiB)
1-data.png (25.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered cooldadtx commented

500 indicates a server side error so the problem is in your C# code. This is where standard debugging comes into play as we have no way of debugging your really, really long query to figure out what is wrong.

  1. Set a breakpoint at top of your action method.

  2. Start the debugger.

  3. Navigate in your app until the action method is called.

  4. Step through your code.

  5. When exception occurs the debugger will tell you exactly what is wrong and where it failed.

  6. Provide all that information so somebody can help you if you are unable to figure it out on your own.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

101512-1-data.png



i did all that steps
and This is the last statement in my c# code that returned to view

and everything seems right to me

0 Votes 0 ·
1-data.png (25.7 KiB)

You're using LINQ which uses deferred execution. Put a call to ToArray to force the execution of the query before it gets returned to the runtime.

var data = ...

//Will  likely fail here and give you the exception
var results = data.ToArray();

return Json(results);
0 Votes 0 ·
DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered DuaneArnold-0443 edited

@khamissafy-6344

A HTTP 500 means a .NET exception was thrown, and it was unhandled by the .NET code. So the Web server IIS swallowed the exception and returned the HTTP 500.

You should be trying to implement global exception handling in the ASP.NET Core MVC solution to find out what the exception is about by logging the exception and showing a user friendly error page.

https://stackify.com/csharp-catch-all-exceptions/

The GitHub solution is doing global exception handling that is logging the exception using Serilog in the Core MVC project. No try/catch is in any code, or in any code the MVC project references all exceptions are caught by the global exception handler.

https://github.com/darnold924/PublishingCompany

HTH

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.