Azure移动服务 - 自定义API在本地运行,但在部署到Azure时获得404

时间:2016-01-12 22:35:48

标签: c# api azure asp.net-web-api2 azure-mobile-services

我已经创建了一个基于.net Web Api的Azure Mobile服务,它已经运行了一段时间,表格运行良好 - 按预期返回数据。

我最近添加了一个自定义API控制器

public class FitbitWebApiController : ApiController
{
    public ApiServices Services { get; set; }

    // GET api/FitbitWebApi
    public string Get()
    {
        Services.Log.Info("Hello from custom controller!");
        return "Hello Friend";
    }

}

我希望能够通过将/ Api / FitbitWebApi添加到我的服务网址来访问此API。

当我在本地运行时 - 是localhost:118 / api / FitBitWebApi工作正常但是当我将其部署到Azure时,我得到了404错误。

事实上 - 当我查看azure日志时,我收到以下错误消息

详细错误信息: Module __DynamicModule_Microsoft.Owin.Host.SystemWeb.OwinHttpModule,Microsoft.Owin.Host.SystemWeb,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35_2ded9ca3-2357-42a5-8002-51c7cdf0ab1c 通知MapRequestHandler Handler ExtensionlessUrlHandler-Integrated-4.0 错误代码0x00000000 请求的网址http://mobl_m_pedgservice:80/api/FitbitWebApi

不确定如何,但现在Azure似乎已将mobl_m添加到我的网址的开头

有人有任何想法吗?

Azure日志的完整错误跟踪是:

<h3>HTTP Error 404.0 - Not Found</h3> 
<h4>The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</h4> 
</div> 
<div class="content-container"> 
<fieldset><h4>Most likely causes:</h4> 
<ul>    <li>The directory or file specified does not exist on the Web server.</li>  <li>The URL contains a typographical error.</li>    <li>A custom filter or module, such as URLScan, restricts access to the file.</li> </ul> 
</fieldset> 
</div> 
<div class="content-container"> 
<fieldset><h4>Things you can try:</h4> 
<ul>    <li>Create the content on the Web server.</li>  <li>Review the browser URL.</li>    <li>Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>. </li> </ul> 
</fieldset> 
</div> 

<div class="content-container"> 
<fieldset><h4>Detailed Error Information:</h4> 
<div id="details-left"> 
<table border="0" cellpadding="0" cellspacing="0"> 
<tr class="alt"><th>Module</th><td>&nbsp;&nbsp;&nbsp;__DynamicModule_Microsoft.Owin.Host.SystemWeb.OwinHttpModule, Microsoft.Owin.Host.SystemWeb, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35_2ded9ca3-2357-42a5-8002-51c7cdf0ab1c</td></tr> 
<tr><th>Notification</th><td>&nbsp;&nbsp;&nbsp;MapRequestHandler</td></tr> 
<tr class="alt"><th>Handler</th><td>&nbsp;&nbsp;&nbsp;ExtensionlessUrlHandler-Integrated-4.0</td></tr> 
<tr><th>Error Code</th><td>&nbsp;&nbsp;&nbsp;0x00000000</td></tr> 

</table> 
</div> 
<div id="details-right"> 
<table border="0" cellpadding="0" cellspacing="0"> 
<tr class="alt"><th>Requested URL</th><td>&nbsp;&nbsp;&nbsp;https://mobl_m_pedgservice:80/api/Fitbit</td></tr> 
<tr><th>Physical Path</th><td>&nbsp;&nbsp;&nbsp;C:\Program Files (x86)\SiteExtensions\MobileServicesDotNet\1.0.478\api\Fitbit</td></tr> 
<tr class="alt"><th>Logon Method</th><td>&nbsp;&nbsp;&nbsp;Anonymous</td></tr> 
<tr><th>Logon User</th><td>&nbsp;&nbsp;&nbsp;Anonymous</td></tr> 

</table> 
<div class="clear"></div> 
</div> 
</fieldset> 
</div> 

<div class="content-container"> 
<fieldset><h4>More Information:</h4> 
This error means that the file or directory does not exist on the server. Create the file or directory and try the request again. 
<p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&amp;IIS70Error=404,0,0x00000000,9200">View more information &raquo;</a></p> 
<p>Microsoft Knowledge Base Articles:</p> 

1 个答案:

答案 0 :(得分:0)

我今天又看了一下Azure门户上的日志,发现了以下错误:

      HttpStatus    405
      HttpReason    Method Not Allowed

这导致我得到以下答案:Stackoverflow - asp-net-wenapi 405 errors

我修改了网络配置以包含:

<system.webServer>
  <modules>
    <remove name="WebDAVModule" />
  </modules>
  <handlers>
    <remove name="WebDAV" />
  </handlers>
</system.webServer>

这解决了这个问题 - 现在API按预期调用了!