c# - How to handle WebApi error 404 -


i'm implementing mvc 5 application webapi2 in same domain. problem how handle error 404 in webapi. i'm using routing in webapi.

[routeprefix("myapi")] public class myapicontroller : apicontroller  { [route("value")] public string myvalue() { return "value"; } } 

now have url "/myapi/value" returns value string. problem requested "/myapi/value/bla/bla" or url not in api, returns error 404.

i tried link http://weblogs.asp.net/imranbaloch/handling-http-404-error-in-asp-net-web-api, applies in webapi project not in mvc + webapi project.

please help. tia

update:

please read carefully!!!!

this default page if don't handle 404 in webapi. includes here physical path.

enter image description here

updated:

i think following has better description on how implement error handling webapi 2+ project: http://www.asp.net/web-api/overview/error-handling/web-api-global-error-handling .

there 2 problems had in projects when combining mvc , webapi in same project.

the first being error handling of normal mvc pages did not work anymore. resolve initialized webapi routing first, on mvc controller routing , made small adjustments in web.config described in post.

secondly if want handle invalid webapi routings, example correct directory wrong values can not resolved. try solution in "global error handling" section of below link: http://weblogs.asp.net/jongalloway/looking-at-asp-net-mvc-5-1-and-web-api-2-1-part-4-web-api-help-pages-bson-and-global-error-handling


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -