Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
803 views
in Technique[技术] by (71.8m points)

.net - Web API interface works locally but gets 404 after deployed to Azure Website

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.

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:

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

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

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...