ASP.NET MVC pretty URLs on steroids

Tags: .net, mvc, t4mvc, performance

There is something wrong

As you may know, there's a little problem with the attribute routing in ASP.NET MVC: generating a link (via Html.ActionLink) might get real slow when you've got hundreds of attributed actions.

The answer to this issue is to use named routes, so instead of Html.ActionLink you use Html.RouteLink, but that's not quite handy, at least for me it isn't. Given that I'm used to T4MVC, it seems like a step back.

So I decided to address this issue and contributed (yay!) to the T4MVC itself and recently my small pull request has been accepted by David Ebbo, who then released it (currently in beta - T4MVC 4.0.0-beta1).

Grab it when it's hot

You can grab the fresh, hot NuGet here: Install-Package T4MVC -Pre

This release adds two things (*): the AutoNamedRouteAttribute and Html.AutoNamedRouteLink extension method.

The first one, AutoNamedRouteAttribute, is just a drop-in replacement for regular RouteAttribute you use when defining routes for your actions. This new attribute basically just creates a new route, with an automatically generated name for given action using the pattern:


(with some placeholder when there's no area present).

The Html.AutoNamedRouteLink is a replacement for Html.ActionLink to generate a link. From T4MVC ActionResult that you pass to it (exactly the same as for Html.ActionLink) and it pulls out the area, controller and action. It then regenerates route name the same way the AutoNamedRouteAttribute generates it. Finally, it just calls Html.RouteLink behind the scenes to generate a link.

Those two small additions add significant performance gain in some cases. You can see it for yourself since the updated host website in T4MVC now contains a sample with many controllers.

After playing a little bit with this new T4MVC version, I think I might have forgotten about Url.Action that has the same problems as Html.ActionLink and needs "fixing". Silly me, but I'll try to do something about it soon.

Speaking about the Open Source

Since we are in the OSS context, I also did some contribution to a very nice LiczbyNaSlowaNET polish library that, well, does what the name says (yes, I'm mean to all those non-polish guys out there - go figure it out and write in comments if you dare).

I also made a contribution do MPAndroidChart, but it's still waiting for a merge. You can post a comment here, maybe it'll speed some things up?

Oh, and if you're using Certify to generate Let's Encrypt certificates, be sure to update to the newest version since it fixes some annoying issues and now bundles ACMESharp Powershell scripts so hopefully there won't be any more problems like those.

(*) well, it also bumps up ASP.NET MVC dependency to at least 5.2.2 (AFAIR) but hey - the newer, the better, right? RIGHT?!

Read also

The ugly truth behind pretty URLs

Attribute routing is quite handy feature of ASP.NET MVC. But it can also be the reason your web app is so slooow.

T4MVC model unbinders

Sometimes you need to write some infrastructure code just to get basic stuff working. I don't like it either, so here're some tips about T4MVC that might ease your pain.

web.config tips: HTTP to HTTPS redirects and disable access to folder

This is just a quick note with few (I hope) useful web.config tips/settings regarding HTTP -> HTTPS redirects and disabling external access to a folder.