GGleGrand
GGleGrand

Reputation: 1650

Asp.net WebApi2 default routing not finding different named apis?

I have two WebApi2 actions, each work fine alone:

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

and

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

When they are both present, I get a 404 error for both. What must I do to make both POST .../ChangeEmail and .../MigrateUser be found? Is there a way to do this without explicit Attribute Based routing (which would be?).

The following HttpGet work fine, no Route() required...

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

and

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

Upvotes: 3

Views: 39

Answers (1)

gaurav bhavsar
gaurav bhavsar

Reputation: 2043

Use Route attribute to diff. each action.

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

and

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

Upvotes: 1

Related Questions