如何使用Visual Studio 2017将ASP.NET Web API 2项目发布到IIS 8.5?

时间:2021-08-07 03:33:49

I have an ASP.NET Web API 2 project that compiles and works as expected on my local machine, but when I publish to my IIS 8.5 server, all my requests just come back with status code 500 server error. No additional information is given. This is my first time attempting to publish a Web API.

我有一个ASP.NET Web API 2项目,在我的本地计算机上编译并按预期工作,但是当我发布到我的IIS 8.5服务器时,我的所有请求都返回状态代码500服务器错误。没有提供其他信息。这是我第一次尝试发布Web API。

I have made a site in IIS, configured it the same as other sites I've made, and set it to HTTPS only. I believe the site is configured correctly because I have a basic default.html page that I can easily connect to, but I just can't seem to make any API calls. I'm using Postman to test my API calls.

我在IIS中创建了一个站点,将其配置为与我制作的其他站点相同,并将其设置为仅HTTPS。我相信网站配置正确,因为我有一个基本的default.html页面,我可以轻松连接到,但我似乎无法进行任何API调用。我正在使用Postman来测试我的API调用。

In Visual Studio, I've used Web Deploy, Web Deploy Package and File System Publish options. Using the "Precompile during publishing" option for the latter two does not appear to make a difference.

在Visual Studio中,我使用了Web Deploy,Web Deploy Package和File System Publish选项。对后两者使用“发布期间的预编译”选项似乎没有什么区别。

Web Deploy refuses to validate the connection, saying that it can't connect to the remote computer and to make sure Web Deploy is installed. I can verify it is through "Programs and Features", and I've tried just about every combination of URI I can think of to get it to connect with no avail. The error directs me to this Microsoft troubleshooting page, but the commands suggested don't seem to work.

Web Deploy拒绝验证连接,说它无法连接到远程计算机并确保安装了Web Deploy。我可以通过“程序和功能”验证它,并且我已经尝试了几乎我能想到的每个URI组合,以使它无法连接。该错误将我引导至此Microsoft故障排除页面,但建议的命令似乎不起作用。

Web Deploy Package allows me to create a .zip on my local file system which I then transfer to the hosting server and import using Web Deploy from IIS. The screenshot below is what I see in the IIS website's root directory after import. I manually add the HTML file for testing as it's not part of my application. The bin folder appears to contain all the necessary DLL files.

Web Deploy Package允许我在我的本地文件系统上创建一个.zip,然后将其传输到托管服务器并使用IIS中的Web Deploy导入。下面的屏幕截图是我在导入后在IIS网站的根目录中看到的内容。我手动添加HTML文件进行测试,因为它不是我的应用程序的一部分。 bin文件夹似乎包含所有必需的DLL文件。

如何使用Visual Studio 2017将ASP.NET Web API 2项目发布到IIS 8.5?

File System Publish outputs the same structure as Web Deploy Package, with no difference in behavior.

文件系统发布输出与Web Deploy Package相同的结构,行为没有区别。

Is there something I've been missing? I just don't know what else to troubleshoot.

有什么我一直在想的吗?我只是不知道还有什么可以排除故障。

1 个解决方案

#1


0  

To repeat @n.piskunov's comment, my app did not have any error details policy. This article by Jimmy Bogard explains that Web API doesn't respect the web.config file's customErrors setting, which is what I was using. It also explains how to fix said issue.

要重复@ n.piskunov的评论,我的应用程序没有任何错误详细信息策略。 Jimmy Bogard撰写的这篇文章解释说,Web API不尊重web.config文件的customErrors设置,这正是我所使用的。它还解释了如何解决所述问题。

With detailed error messages enabled, I was able to figure out that the target framework was not installed on the server. Installing the correct target framework solved my issue.

启用详细的错误消息后,我能够发现服务器上没有安装目标框架。安装正确的目标框架解决了我的问题。

#1


0  

To repeat @n.piskunov's comment, my app did not have any error details policy. This article by Jimmy Bogard explains that Web API doesn't respect the web.config file's customErrors setting, which is what I was using. It also explains how to fix said issue.

要重复@ n.piskunov的评论,我的应用程序没有任何错误详细信息策略。 Jimmy Bogard撰写的这篇文章解释说,Web API不尊重web.config文件的customErrors设置,这正是我所使用的。它还解释了如何解决所述问题。

With detailed error messages enabled, I was able to figure out that the target framework was not installed on the server. Installing the correct target framework solved my issue.

启用详细的错误消息后,我能够发现服务器上没有安装目标框架。安装正确的目标框架解决了我的问题。