简体   繁体   English

Asp.Net Core-无故返回500

[英]Asp.Net Core - Returns 500 for no reason

I'd like to ask for help with this weird behaviour. 我想就这种奇怪的行为寻求帮助。

I have Asp.Net Core (.Net Core version 2.0) application, which runs without problems on my Windows 10 machine, but when I publish it to Debian server, it starts acting weird. 我有Asp.Net Core(.Net Core版本2.0)应用程序,该应用程序在Windows 10计算机上运行没有问题,但是当我将其发布到Debian服务器时,它开始表现异常。 I've verified files, the sha1 of application that works on Windows is the same as sha1 of application that acts weird on Debian. 我已经验证了文件,在Windows上运行的应用程序sha1与在Debian上运行异常的应用程序sha1相同。

It has multiple controllers with no views - they work without problem (I just return ObjectResult from them). 它有多个没有视图的控制器-它们可以正常工作(我只是从中返回ObjectResult)。 And I have one controller that uses View and whenever I try to call it on Debian server, it returns 500 Internal Server Error without any information - just empty response. 我有一个使用View的控制器,每当我尝试在Debian服务器上调用它时,它都会返回500 Internal Server Error,而没有任何信息-只是空响应。 I tried uploading debug version to the server, i tried encapsulating the controller methods into try-catch, but everything is still the same -> empty 500 response. 我尝试将调试版本上传到服务器,尝试将控制器方法封装到try-catch中,但是一切仍然相同->空500响应。

Summary: 摘要:

+------------+----------+----------+
|            | Windows  | Debian   |
+------------+----------+----------+
| Controller | OK       | OK       |
| w/o view   |          |          |
|            |          |          |
| Controller | OK       | 500 Err  |
| with view  |          |          |
+------------+----------+----------+

No error message, try-catch doesn't do anything, debug mode doesn't do anything. 没有错误消息,try-catch不执行任何操作,调试模式不执行任何操作。

Here is log: https://pastebin.com/22AC8d4G The funny thing is, that I HAVE Form.cshtml in /View/HouseForm : http://prntscr.com/jytj0f - and I tried to put it in /View/Shared as well. 这是日志: https ://pastebin.com/22AC8d4G有趣的是,我在/ View / HouseForm中拥有Form.cshtml: http ://prntscr.com/jytj0f-我试图将其放入/ View /也共享。 It works on Windows, but doesn't work on Debian. 它适用于Windows,但不适用于Debian。 Probably .Net Core issue? 可能是.Net Core问题?

If you need any additional information, leave a comment and I'll edit this question. 如果您需要任何其他信息,请发表评论,我将编辑此问题。

Ok, here's the problem: 好的,这是问题所在:

As shown in the log, Asp couldn't find the view file. 如日志所示,Asp找不到视图文件。 It worked on Windows, because on Windows, startup path was set one level above the /Views folder. 它在Windows上有效,因为在Windows上,启动路径设置为/ Views文件夹上方的一级。 But on Debian, startup path was set two levels above the /Views folder. 但是在Debian上,启动路径在/ Views文件夹上方设置了两个级别。 So I had to add this to Program: 所以我必须将其添加到程序中:

        if (Directory.GetCurrentDirectory().EndsWith("3step"))
            Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "publish"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM