我如何可以覆盖我的路由表中的.svc文件? [英] How can I override a .svc file in my routing table?

查看:139
本文介绍了我如何可以覆盖我的路由表中的.svc文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个URL,它是从一些JSON使用后从主站回:

I have this URL that was used from some JSON post back from the main website:

HTTP://site/Services/api.svc/UpdateItem

我们都在慢慢地更新网站,ASP.Net MVC 2的过程,不想打破任何当前URL的系统。 (Jav​​aScript的刷新问题)

We are in the process of updating the web site slowly to ASP.Net MVC 2 and don't want to break any current URL's in the system. (JavaScript refresh issues)

我删除了/Services/api.svc和移动了逻辑此API调用分为以下控制器:

I have deleted the /Services/api.svc and have moved the logic for this API call into the following Controller:

的http://网站/ LegacyApi /的updateItem

不幸的是,在添加路由时,我似乎无法得到它的覆盖api.svc和不断得到一个404错误。

Unfortunately, when adding the route, I can't seem to get it to override the api.svc and keep getting a 404 error.

路线:

    routes.MapRoute(
        "UpdateItemApi",
        "Services/api.svc/UpdateItem",
        new { controller = "LegacyApi", action = "UpdateItem" }
    );

根据<一href=\"http://msdn.microsoft.com/en-us/library/cc668201.aspx#scenarios_when_routing_is_not_applied\">MSDN在这个具体问题,路由应该通过。

任何帮助是极大的AP preciated。

Any help on this is greatly appreciated.

路由标准的.aspx页面按预期正常运行,因此这似乎有什么东西perticular与.SVC文件以及它们是如何处理的。

Routing for standard .aspx pages works as intended, so this seems to be something perticular with the .svc files and how they are handled.

推荐答案

您正在运行到这个问题是由于注册了.SVC文件的生成提供。此版本提供由默认计算机级别的web.config文件中注册。

The problem you're running into is due to a build provider that is registered for .svc files. This build provider is registered by the default machine level web.config file.

为了让路由在这种情况下工作,你需要删除应用程序的web.config文件的生成提供。下面的代码片段显示了如何从构建提供商列表中删除.svc扩展名。

In order to get routing to work in this case, you'll need to remove the build provider in your application's web.config file. The following snippet shows how to remove the .svc extension from the list of build providers.

  <system.web>
    <compilation debug="true" targetFramework="4.0">
        <buildProviders>
            <remove extension=".svc"/>            
        </buildProviders>
    ...

这篇关于我如何可以覆盖我的路由表中的.svc文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆