asp.net-mvc ASP.NET MVC 中的 500 内部服务器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2996139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:21:23  来源:igfitidea点击:

500 Internal Server Error in ASP.NET MVC

asp.net-mvc

提问by Renu123

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

我在 ASP.NET MVC 中工作。我正在使用部分视图,但是当我单击特定链接时,出现以下错误。

500 Internal Server Error

500内部服务器错误

How can this error be fixed?

如何修复此错误?

采纳答案by Tom Gullen

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

500 服务器错误意味着脚本抛出了错误,这不是断开的链接(也称为 404 错误)。

If you are using Internet Explorer, go to tools > options > advancedand 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.

如果您使用的是 Internet Explorer,请转到tools > options > advanced并取消选择friendly http errors,这将为您提供更全面的错误描述,以便您可以调试脚本,或联系相关人员进行调试。

回答by Bronek

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.

要检查导致 ASP MVC 下内部服务器 500 错误的原因,您还可以在调试模式下运行您的应用程序并检查属性 AllErrors。
该属性是一个异常类型元素的数组。

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

要执行此操作,请打开Global.asax.cs(C#) 并在类MvcApplicationput 方法的主体中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

然后设置断点并检查数组的内容: this.Context.AllErrors

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

它帮助我解决了抛出的异常并可选择查看堆栈跟踪。

回答by anu

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

尽管有点晚,但作为安全措施,Anti-Forgery 令牌会阻止请求。

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

删除 .cshtml 和控制器中的所有防伪标签,为我删除了错误。

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

但是,如果您想成功保留这些令牌,请使用此链接:- http://iamdotnetcrazy.blogspot.com/2013/08/how-to-solve-anti-forgery-token-could.html

回答by sree

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

我从 Windows 事件查看器(运行>eventvwr.msc>Windows 日志>应用程序)中获得了有关错误的更多详细信息。检查从 w3wp.exe 记录的警告/错误

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

在我的情况下,原因是缺少 dll。希望这可以帮助