Multiple actions were found that match the request

alattin (16999) 6 yıl önce sordu

Web API üzerinde bir metoda erişmek istediğimde aşağıdaki hatayı aşıyorum.

{"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: GetNotification on type Controller\r\nGetSubscribe on type  Controller","ExceptionType":"System.InvalidOperationException","StackTrace":" 

Multiple actions were found that match the request hatasının çözümü nedir?

Toplam 1 cevap


alattin (16999) 6 yıl önce cevapladı

Multiple actions were found that match the request hatasının çözümü nedir?

Web API üzerinde bir metoda erişmek istediğinizde Multiple actions were found that match the request hatası alıyorsanız route ile ilgili bir hatadan dolayı olma ihtimali çok yüksektir. Projenizde App_Start klasöründeki WebApiConfig dosyasını açın. Bu dosyada şu şekilde bir kod göreceksiniz:

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

 

Bu kodu aşağıdaki gibi düzeltin:

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

Burada iki kod arasındaki fark ikinci kodda yönlendirmeye action eklenmesidir. İlk yönlendirmede herhangi bir action'a yönlendirme yapılmadığından varsayılan ilk metoda yönlendirme yapılacaktır.