29

I am working in ASP.NET MVC. I am using partial views, but when I clicked on particular link I got the following error.

500 Internal Server Error

How can this error be fixed?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Renu123
  • 1,325
  • 6
  • 18
  • 25
  • Turn off friendly error messages in your browser, and allow debugging in your application, and then tell us the error so that we can help you better. – Sev Jun 08 '10 at 09:34
  • 2
    The advice here on getting your server to return you more detailed error information may be helpful: http://stackoverflow.com/q/5385714/12484 – Jon Schneider Jun 07 '16 at 13:37

4 Answers4

62

To check what causes Internal Server 500 Error under ASP MVC you can also run your app in debug mode and check property AllErrors.
The property is an array of Exception type elements.

To do this open Global.asax.cs (C#) and in the body of class MvcApplication put method Application_EndRequest:

protected void Application_EndRequest()
{   //here breakpoint
    // under debug mode you can find the exceptions at code: this.Context.AllErrors
}

Then set breakpoint and check contents of the array: this.Context.AllErrors

It helped me to resolve what exception was thrown and optionally to see the stacktrace.

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
Bronek
  • 10,722
  • 2
  • 45
  • 46
  • 1
    Great answer! I've tried checking the network tab but it never gave me a detailed error. It just stated that it failed to load the resource. This solution pointed out there was a issue with my viewmodel's constructor. Thanks! – usr4896260 Mar 06 '17 at 15:15
  • 1
    what if I get `this.Context.AllErrors` to null? – Hakan Fıstık Jul 29 '17 at 07:37
  • i tried this solution but i got this.Context.AllErrors = null... so after digging it more i found out that in my model which i have bound to form i have decorated one of integer property with "[MaxLength(6, ErrorMessage = "Pincode should be valid.")]" after removing this it worked fine for me. – Snziv Gupta Oct 04 '17 at 12:00
  • where i can find : `this.Context.AllErrors` ? – Riadh Saïd Oct 02 '20 at 02:14
7

500 Server error means that a script has thrown an error, this is not a broken link (aka a 404 error).

If you are using Internet Explorer, go to tools > options > advanced and unselect friendly http errors, this will give you a more comprehensive description of the error so you can debug the script, or contact the relevant people to debug it.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
5

I got more details of the error from windows event viewer(Run>eventvwr.msc>Windows Logs>Application). Check the warnings/errors recorded from w3wp.exe

In my case the reason was missing dlls. Hope this helps

sree
  • 2,287
  • 28
  • 26
  • upgrading from .net core to .net 5.0 was throwing 500 internal error on server & clueless after a days work, the page was coming blank & no detailed information even after setting customErrors to true in web.config, with information in the Application able to figure out that there is a know issue https://docs.telerik.com/reporting/knowledge-base/binaryformatter-exception-after-upgrade-to-net5 – Naga Dec 24 '20 at 18:34
2

Though a little late, the Anti-Forgery token blocks the request as a security measure.

Removing all those anti-forgery tags in .cshtml and controller, removed the error for me.

Though if you want to keep those tokens successfully use this link:- http://iamdotnetcrazy.blogspot.com/2013/08/how-to-solve-anti-forgery-token-could.html

anu
  • 305
  • 1
  • 5
  • 14