Web API 2: OData 4: Actions returning 404

时光毁灭记忆、已成空白 提交于 2019-12-01 20:38:18

This may be caused by the routing convention of IIS, which would have its own routing rule when Uri contains dot. In odata v4, however, all function/action calls are required to be namespace qualified. Then there would be a dot appearing in such Uri, which would be mis-handled by IIS.

To get rid of this, you could try either of followings:

  1. Turn on runAllManagedModulesForAllRequests, add the following in Web.config

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

But there can be some potential issue for this option, please refer to this post for detail.

  1. Turn on project specific settings, add the following in Web.config:

    <system.webServer>
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="odata/cms*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
    </system.webServer>

I had the same problem and I solved adding a trailing slash to the url. In your case it would be /odata/cms/Pages/Translate/

Matt

Well, it was almost a year after this question that I actually tried moving to OData v4 again and had the same problem. I forgot about my original question here and asked a new one and then found the answer. See OData v4 Function always returns 404 for more details. I'm glad to say all is working well now.

Achilles Froes

Do you use Entity Framework Database First Approuche? Take a look at navigation properties, at serialization time they may be holding. In my case, I remove all the navigation properties just for testing, and it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!