如果Web API在本地主机上工作,它将停止在Azure网站上工作。ASP.NET Web API无法在Azure上工作
的错误是无法加载资源:服务器与404(未找到)状态回应或您正在寻找已被删除的资源,有其名称更改,或者暂时不可用。在浏览器中将URL粘贴到api时的。
注意: 我从来没有遇到过这个错误,并且我已经有几个站点已经使用Web Api属性路由的Azure。
WebConfig
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
RouteConfig
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Cities",
url: "Cities/{id}/{name}/{action}",
defaults: new { controller = "Cities", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
的Global.asax
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Goggling透露,这是一个常见的问题:
HTTP 404 Page Not Found in Web Api hosted in IIS 7.5
WebAPI DELETE request return 404 error in Azure
WebApi and ASP.NET 4 routing issues
Configuring IIS methods for ASP.NET Web API on Windows Azure Websites
How Extensionless URLs Are Handled By ASP.NET v4
Getting 404 from WebAPI on Windows Azure Web Sites
ASP.NET MVC 4 and Web API in Azure - No HTTP resource was found
MVC 4.5 Web API Routing not working?
UPDATE
尝试后每一个方法在上面我已经删除了所有* .DLL文件从溶液中的链接提示,创造了一个新的MVC + Web API项目并将* .dlls添加到解决方案。建设和一切按照预期工作在第一位。
什么是您试图访问的URL? – pollirrata
您应该启用CORS。 –
@ThiagoCustodio这里不需要CORS。 –