网络API接口本地工作,但部署到Azure的网站后获得404 [英] Web API interface works locally but gets 404 after deployed to Azure Website

查看:195
本文介绍了网络API接口本地工作,但部署到Azure的网站后获得404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个ASP.NET MVC 4的网站。加上MVC控制器,我有一个包含一个Ajax GET API接口由一个API控制。当使用Visual Studio调试本地它完美。

I'm working on a ASP.NET MVC 4 website. Together with MVC controllers, I have one API controller which contains an ajax GET API interface. It works perfectly when debugged locally with visual studio.

然而,当我部署它作为一个Azure的网站,MVC控制器,但该API控制器不工作了。当jQuery的code试图去实现它,它返回像回应:

However, after I deployed it as an Azure Website, MVC controllers work, but the API controller doesn't work anymore. When jQuery code tries to reach it, it returns a response like:

没有HTTP资源发现匹配的请求URI http://example.com

No HTTP resource was found that matches the request URI 'http://example.com'.

看起来至少航线作品(否则,另一个404响应体返回)。

It looks like at least the route works (otherwise, another 404 response body is returned.).

此外,我有部署为Azure的云服务的另一个纯MVC 4个Web API服务。它完美的作品。因此,我不知道是什么原因导致MVC网站里面的API失败?谢谢!

Additionally, I have another pure MVC 4 Web API service deployed as an Azure Cloud Service. It works perfectly. Thus, I wonder what causes the API inside MVC Website to fail? Thank you!

推荐答案

这是一个常见的​​问题,当一个MVC应用程序部署在IIS上,它是通过调用您的Web API将改变暴露了REST服务的HTTP URL。如果您的API控制器命名为MyApiController,所以在生产环境现状,应该调用URL前添加应用程序的名称。这意味着/ API / MyApi将成为/ MyApp的/ API / MyApi。 MyApp的是你的网站的preFIX(yourwebsite / MyApp的)。

It is a common problem When an MVC application is deployed on IIS, the HTTP url which is calling the REST Service exposed by your web API will change. If your api controller is named MyApiController, so in production evironment, you should add the application name before the calling URL. That means that /api/MyApi will become /MyApp/api/MyApi. MyApp is the prefix of your web site (yourwebsite/MyApp).

这篇关于网络API接口本地工作,但部署到Azure的网站后获得404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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