ASP.NET WEB API 2在本地,不适用于生产Web服务器 [英] ASP.NET WEB API 2 Works Locally But Not On Production Web Server

查看:123
本文介绍了ASP.NET WEB API 2在本地,不适用于生产Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个新的Web API 2在本地的伟大工程,但是当我上传同样的code到我的生产服务器(Arvixe在这种情况下)我得到的是404,当我把它。我花了几个小时在网上搜索,阅读论坛等。并且已经能够找到没有解决,所以我问这里是我最后的努力。

I've developed a new WEB API 2 that works great locally, however when I upload the same code to my production server (Arvixe in this case) all I get is a 404 when I call it. I've spent HOURS searching the web, reading forums, etc.. and have been able to find no resolution, so I'm asking here as my last effort.

我目前只与被创建的默认测试项目中,当你做的新建项目>的ASP.NET Web API 2空项目在Visual Studio。这将创建一个空项目Values​​Controller 。您应该能够通过名为 JSON响应/ API /值,但这甚至不工作。

I'm currently only testing with the default project that gets created when you do New Project > ASP.NET Web API 2 Empty Project in Visual Studio. This creates an empty project with a single ValuesController. You should be able the JSON response by called /api/values, but this doesn't even work.

我使用招本地和Web服务器上测试的API。

I'm using Fiddler to test the API locally and on the web server.

http://localhost:1993/api/values    <--- works great

http://api.mydomain.com/api/values   <--- returns 404

请注意:我创建在这种情况下的子域API,但一切都为code的API是创建时的持平。

Note: I created a subdomain "api" in this case, but everything for the code for the API is unchanged from when it was created.

为什么在世界上在本地而不是做这项工作的生产Web服务器上?

Why in the world does this work locally but not on the production web server?

推荐答案

注意:我创造了在这种情况下的子域API,但一切都为code的API是创建时的持平。

"Note: I created a subdomain 'api' in this case, but everything for the code for the API is unchanged from when it was created."

以上您的评论是可疑的,你应该公布在根目录下你的WEB API应用程序。就像如果 http://example.com 指向myexample中文件夹中,然后应用程序应该在myexample中文件夹中公布。
之后,你就可以访问你的API使用 http://example.com/api/ {}控制器/ {}行动

Above comment of your's is suspicious, you should publish your WEB API application in the root directory. Like if http://example.com is pointing to "MyExample" folder, then application should be published on "MyExample" folder. After that you will be able access your api with http://example.com/api/{controller}/{action}

这篇关于ASP.NET WEB API 2在本地,不适用于生产Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆