Posted on: 8/9/2013 2:38:48 PM | Views : 319

The situation: I read this guide to try and create a mobile-optimized version of my C# ASP.NET website. In doing so, I created a Mobile.master file, (presently just a straight copy of my existing master page,) and included the following code within one of my .aspx.cs files, which use master pages:
protected void Page_PreInit(object sender, EventArgs e) { if (Request.Browser.IsMobileDevice) MasterPageFile = "~/Mobile.master"; else MasterPageFile = "~/Site.master"; } The issue: I receive the following error upon loading the page in question from a mobile device:
System.InvalidCastException: Unable to cast object of type 'ASP.mobile_master' to type 'ASP.site_master'.
...

Go to the complete details ...