As we know that routing follows the routes provided in RegisterRoutes function in RouteConfig.cs which defines the controller and action in default routes.
My project only have default route like:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
So how does routing detects that whether we are accessing some action or pointing to a file like image, css or js.
The short answer is that any request for a resource that has a . in its name is directly served by IIS without invoking MVC routing. Conversely, requests that do not contain a . are passed to MVC for routing. Importantly this is just default behaviour.
As a quick test, fabricate a url for any resource that does not exist in your project such as \asdf
and note the 404 error generated by MVC. Now repeat the test with \asdf.asdf
and note the 404 error is generated by IIS.
It is possible to change this behaviour with directives in web.config. For example, see How do I route images using ASP.Net MVC routing?