Poor performance and slow website using MVC 5 attribute routing

I am developing a site on Azure, with mvc5. I use attribute routing, with routes and route prefix on controllers. I am calling with the action.link helper. I did not name my routes.

I did the following on my route.config:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); routes.LowercaseUrls = true; routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 

My controllers:

 [OutputCache(Duration = 600, Location = System.Web.UI.OutputCacheLocation.Client)] [RoutePrefix("istanbul/kadikoy")] [Route("{action=index}")] public class KadikoyController : Controller { public ActionResult Index() { return View(); } [Route("kadikoy-tarihi")] public ActionResult KadikoyTarihi() 

I have very low performance since the server response time, i.e. 9.6 s

If I comment on the attributes of the routing codes with default routing, I have a server response time of 2.1 s.

Thank you for your responses.

+5
source share
1 answer

It turns out that the really expensive bit of this operation does not display your attribute routes, this is before it happens. MVC needs to create a ControllerFactory and get all types of controllers. This process is 1245 ms in my project, and the rest of the MapMvcAttributeRoutes () functions take about 45 ms. I assume that if you do not use attribute routing, controllers will be found as needed, and not immediately.

0
source

Source: https://habr.com/ru/post/1212965/


All Articles