Thursday, 11 March 2021

MVC - WebApiConfing - Controller not called - Fix Error - The resource cannot be found

 

 Watch this example on YouTube


1. View - add error

<script>
    var uri = '/api/test';
    $(document).ready(function () {

        $.ajax({
            url: 'api/test',
            async: true,
            success: function(data){
                alert(data);
            },
            error: function (xhr, status, error) {
                debugger
            }

        });
      
    });
</script> 


2. Global replace

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            WebApiConfig.Register(GlobalConfiguration.Configuration);
        }


with 

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
           
        }

 

1 comment:

  1. This solution for fixing the 'resource cannot be found' error in WebApiConfig is a lifesaver! Just like Host ever provides reliable hosting, resolving these issues ensures your API runs smoothly.

    ReplyDelete