Asp.net WebApi2默认路由没有找到不同的名称apis?

时间:2016-01-08 10:46:55

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

我有两个WebApi2动作,每个动作都很好:

[System.Web.Http.HttpPost]
public async Task<HttpResponseMessage> MigrateUser([FromBody] MigrateUserModel userInfo)

[System.Web.Http.HttpPost]
public async Task<HttpResponseMessage> ChangeEmail([FromBody] ChangeEmailModel model)

当它们都存在时,我都会收到404错误。我该怎么做才能找到POST ... / ChangeEmail和... / MigrateUser?有没有办法在没有明确的基于属性的路由(这将是?)的情况下执行此操作。

以下HttpGet工作正常,不需要Route()...

       [System.Web.Http.HttpGet]
    public async Task<TcMarketUserFullV1> GetIdmCtoUsrFromEmail(string email)

        [System.Web.Http.HttpGet]
    public async Task<TcMarketUserFullV1> GetIdmCtoUsrFromGuid(string ctoguid)

1 个答案:

答案 0 :(得分:1)

使用Route属性进行区分。每一个动作。

[System.Web.Http.HttpPost,Route("migrate")]
public async Task<HttpResponseMessage> MigrateUser([FromBody] MigrateUserModel userInfo)

[System.Web.Http.HttpPost,Route("change")]
public async Task<HttpResponseMessage> ChangeEmail([FromBody] ChangeEmailModel model)