c# - Azure 上无法识别 WebAPI 路由

标签 c# .net azure asp.net-web-api

我正在尝试将 WebAPI 项目部署到 Azure。

它在本地工作。当我将其发布到 Azure 时,我在 Controller 路由上收到 404 错误。

查看日志,我发现路由被作为静态文件处理,而不是通过我的 Controller 。

模块 IIS Web 核心 通知MapRequestHandler 处理程序静态文件 错误代码0x80070002 请求的 URL http://xxxxx:80/api/studies 物理路径 D:\home\site\wwwroot\api\studies 登录方式 匿名 匿名用户登录

我的 Global.asax 是:

    protected void Application_Start()
    {
        GlobalConfiguration.Configure(WebApiConfig.Register);
    }

我的 WebApiConfig.Register 是:

    public static void Register(HttpConfiguration config)
    {
        config.MapHttpAttributeRoutes();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }

我看过类似的问题并尝试调整我的 Web.config 但无济于事。目前看起来像这样(仅相关部分):

<system.webServer>
    <httpErrors existingResponse="PassThrough"/>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
 </system.webServer>

顺便说一下,我使用的是 Entity Framework 6,没有使用 MVC,只是直接使用 WebAPI。

最佳答案

不知何故,我的 Global.asax 被排除在项目之外,因此路由映射从未发生。

关于c# - Azure 上无法识别 WebAPI 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27410271/

相关文章:

c# - 在 rdlc 报告中动态隐藏列

azure - 在Azure Scheduler中,如何以编程方式创建每月定期作业?

c# - .NET 如何检查 Windows 进程是否作为 "App"或 "Background application"运行

java - 如何启用和配置网络安全组的流日志

Facebook 机器人消息不显示空行

c# - Twilio Rest API 抛出错误 : Could not load type 'Twilio.TwilioClient' from assembly 'Twilio, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

c# - 如何将事件添加到 C# 中的包装类?

c# - 使用 MonoTouch 在 iOS 上自定义 Switch

c# - 如何使用 Entity Framework 6 将单个属性映射为多个复合外键的一部分?

.net - 将 pdb 嵌入到程序集中