【问题标题】:WebAPI: Map mutiple URL to same action without using MapHttpAttributeRoutes();Web API:不使用 MapHttpAttributeRoutes() 将多个 URL 映射到同一个操作;
【发布时间】:2017-06-26 07:35:09
【问题描述】:

我需要创建以下三个端点 URL
/测试,
/test/method1
/test/method2

我想将/test/test/method1 视为相同 - 执行相同的任务。
对于/test/method2,执行一些其他操作。

有哪些不同的方法可以实现这一目标?我试过的如下。它适用于前两个 URL,但 /test/method2 不起作用 - 它给出“未找到”异常。

由于一些设计问题,我无法使用GlobalConfiguration.Configuration.MapHttpAttributeRoutes();

【问题讨论】:

    标签: c#-4.0 asp.net-web-api2


    【解决方案1】:

    好的。终于,我明白了。

    我还需要在 Controller 中添加更多操作 Method2(),然后它按预期工作。

    /test - goes to action Method1()
    /test/method1 - goes to action Method1()
    /test/method2 - goes to action Method2()

    【讨论】:

      最近更新 更多