加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – ASP.NET Web API无法在Azure上运行

发布时间:2020-12-16 03:49:03 所属栏目:asp.Net 来源:网络整理
导读:如果Web API在localhost上运行,为什么Web API会停止在Azure网站上运行. 错误是加载资源失败:服务器响应状态为404(未找到)或您要查找的资源已被删除,名称已更改或暂时不可用.在浏览器中将URL粘贴到api时 注意: 我从未遇到过这个错误,我已经在使用Web Api属
如果Web API在localhost上运行,为什么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

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

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项目并将* .dll添加到解决方案中.构建和一切都按预期工作.

解决方法

老帖子,但你试过:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读