Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 696
GGleGrand Avatar asked Feb 26 '26 13:02

GGleGrand


1 Answers

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) 
like image 101
gaurav bhavsar Avatar answered Feb 28 '26 03:02

gaurav bhavsar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!