我正在尝试将 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/