AMP Accelerated Mobile Pages for MVC ASP.Net

Google has a new mobile standard for html that strays from the recent common knowledge involving responsive web pages which show the same html for both mobile and desktop traffic, but which reformats itself to the width of the browser Instead, Accelerated Mobile Pages ( or AMP ) actualy adds a lot of resrictions and some new tags and other goodies with the intention of making the mobile experience much faster. This has been the common compliant I’ve had with the mobile web- even with a powerful smartphone on a fast connection, the web experience is often very slow and just bad. I’m not even sure why some pages are so terrible when they even seem to be built to support mobile, but they just are. This must be the resaoning behind the new AMP standard. 

AMP has recently been in the news because google has indicated that sites supporting AMP will soon receive a bit of an SEO boost. So now, many webmasters who depend on search engine traffic are scrambling to deploy AMP-enabled versions of their sites to take advantage of this slight…advantage. 

Since most of my web projects run on ASP.Net MVC, I’m looking to implement AMP using some boilerplate template code. I’ve checked Nuget and haven’t found anything in there yet. Maybe we’ll have to develop this and add it to the nuget repository. 

Have any of you built or found something to help accelerate developing and/or deploying AMP using .Net MVC? Comment below to discuss further. 

Simplest MVC Controller routing

I’ve ported a number of websites from old static (or nearly so) pages over to more recent .net mvc technology, just for the benefit of being able to use templates and manage/automate a few things better than having to edit individual html files. Yes, Im a fan of Orchard CMS but some of these sites just arent worth the effort of trying to port to Orchard, or at least not for now. Creating a custom theme just for one site just wouldnt be worth the effort.

When doing these kinds of sites, you could use a single “Home” controller for all your pages, and add a controller method for each page. With 20+ pages, you would add a method and a single View for each page you port over… kinda burdensome for a simple site.

So, what I’ll often do is just simplify the Index() method on the controller so it can show the requested view, whatever it may be. You can implement this as follows (yes I’ll add code formatting to this eventually…)-

in HomeController, we add a parameter to the Index() method so we can pass in the name of the view.

public ActionResult Index(string view) {
   return View(view);

In Global.asax, we change the default routing to use:

   “{view}/{id}”, // URL with parameters
   new { controller = “Home”, action = “Index”, view=”Index”, id = UrlParameter.Optional } // Parameter defaults

Now, the default controller “Home” calls Index by default, and passes in the first parameter as the view name. We simply load the view with that name and display it. Note that this route can mess you up fast if you try to do anything fancier, but it’s a good way to simplify a really simple site that is basically a collection of views… perfect for porting over our old pages from and old static site.

MVC Razor Semicolon showing up

If you get a pesky semicolon in your page when using MVC 3 with Razor, you probably did something like this:




See the semicolon? It’s fine to put it there, but of course Razor doesn’t see it as .net code, just more inline html.

This one is obvious once you notice it, but it took me a bit to figure out where it was coming from the first time i encountered it.