ASP.NET Web API在Azure上不起作用 [英] ASP.NET Web API not working on Azure

查看:99
本文介绍了ASP.NET Web API在Azure上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Web API可以在localhost上运行,为什么它会在Azure网站上停止工作.

Why would Web API stop working on Azure Websites if it works on localhost.

错误是无法加载资源:服务器的状态为404(未找到)您正在查找的资源已被删除,名称已更改或暂时不可用.在浏览器中将URL粘贴到api时.

The error is Failed to load resource: the server responded with a status of 404 (Not Found) or The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. when pasting URL to api in browser.

注意: 我从未遇到此错误,并且已经使用Web Api属性路由在Azure上建立了多个站点.

NOTE: I have never encountered this error and I already have several sites already on azure using Web Api attribute routing.

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发现这是一个常见问题:

Goggling revealed that this is a common problem:

​​在网络中找不到HTTP 404页面IIS 7.5中托管的Api

WebAPI删除请求返回404 Azure中的错误

WebApi和ASP.NET 4路由问题

https://stackoverflow.com/questions/15805471/using-windows-azure -websites-with-extensionlessurlhandler

在Windows Azure网站上为ASP.NET Web API配置IIS方法

ASP.NET v4如何处理无扩展名的URL

​​ ASP Azure中的.NET MVC 4和Web API-找不到HTTP资源

MVC 4.5 Web API路由无法正常工作吗?

更新

尝试了上面链接中建议的每种方法后,我从解决方案中删除了所有* .dll,创建了一个新的 MVC + Web API 项目,并将* .dll添加到了解决方案中.首先,构建和所有工作均按预期进行.

After trying every method suggested in the links above i've removed all the *.dlls from the solution, created a new MVC+Web API project and added *.dlls to the solution. Build and everything worked as expected in the first place.

推荐答案

旧帖子,但您是否尝试过:

Old post, but have you tried:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

这篇关于ASP.NET Web API在Azure上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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