title: Parser Error: '_Default' is not allowed here because it does not extend class 'System.Web.UI.Page' & MasterType declaration
body: <p>I recently converted a website project to a web application project in Visual Studio 2008.  I finally got it to compile, and the first page (the login screen) displayed as normal, but then when it redirected to the Default.aspx page, I received an error:</p>
  
  <pre><code>Parser Error Message: 'SOME.NAMESPACE.MyApplicationName.WebApplication._Default' is not allowed here because it does not extend class 'System.Web.UI.Page'.
  </code></pre>
  
  <p>All of my pages inherit from a class called "BasePage" which extends System.Web.UI.Page.  Obviously the problem isn't with that class because the login.aspx page displays without error, and it also inherits from that basepage.</p>
  
  <p>All the pages on the site, including the login page, are children of a masterpage.</p>
  
  <p>After some testing, I have determined what it is that causes the error (although I don't know WHY it does it).</p>
  
  <p>On all the pages where I have the following tag, the error does NOT occur.</p>
  
  <pre><code>&lt;%@ MasterType VirtualPath="~/MasterPages/MainMaster.master" %&gt;
  </code></pre>
  
  <p>On all the pages that do not contain that line, the error DOES occur.  This is throughout the entire application.  I have the tag only on pages where there has been a need to reference controls on the MasterPage.</p>
  
  <p>So, I thought I would just add that line to all my pages and be done with it.  But when I add that line, I get a compile error:
  'object' does not contain a definition for 'Master'</p>
  
  <p>This error is coming from the designer.cs file associated with the ASPX page that I have added the "MasterType" declaration to.</p>
  
  <p>I've forced a rebuild of the designer file, but that doesn't change anything. I compared the content of the Master reference in the designer files between the login.aspx (working) and the default.aspx (not working) but they are exactly the same.</p>
  
  <p>Since I'd really like to get it to work without having to add the "MasterType" declaration to everypage, and since that "fix" isn't working anyway, does anyone know why not having the "MasterType" declaration on an aspx file causes the parser error?  Is there a fix for this?</p>
  
  <p>Example Code:</p>
  
  <p>Here is the code for login.aspx and login.aspx.cs which is working without error:</p>
  
  <p>Login.aspx</p>
  
  <pre><code>    &lt;%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/MainMaster.master" AutoEventWireup="true" Inherits="SOME.NAMESPACE.MyApplicationName.WebApplication.Login" Codebehind="Login.aspx.cs" %&gt;
  &lt;%@ MasterType VirtualPath="~/MasterPages/MainMaster.master" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server"&gt;
      &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;asp:UpdatePanel ID="upLogin" runat="server"&gt;
                  &lt;ContentTemplate&gt;
                      &lt;asp:Panel ID="Panel1" runat="server" DefaultButton="Login1$LoginButton"&gt;
                          &lt;asp:Login ID="Login1" runat="server" LoginButtonStyle-CssClass="button" 
                          TextBoxStyle-CssClass="textBoxRequired" 
                          TitleTextStyle-CssClass="loginTitle"  &gt;
                          &lt;/asp:Login&gt;
                      &lt;/asp:Panel&gt;
                  &lt;/ContentTemplate&gt;
              &lt;/asp:UpdatePanel&gt;
              &lt;asp:UpdatePanel ID="upPasswordRecovery" runat="server"&gt;
                  &lt;ContentTemplate&gt;
                  &lt;asp:PasswordRecovery ID="PasswordRecovery1" runat="server" 
                  SubmitButtonStyle-CssClass="button" TitleTextStyle-CssClass="loginTitle" 
                  SuccessText="Your new password has been sent to you."
                  UserNameInstructionText="Enter your User name to reset your password." /&gt;
                  &lt;/ContentTemplate&gt;
              &lt;/asp:UpdatePanel&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="SideBarPlaceHolder" Runat="Server"&gt;
      &lt;h2&gt;Login&lt;/h2&gt;
      &lt;asp:Button ID="btnCreateAccount" runat="server" Text="Create Account" OnClick="btnCreateAccount_Click" CausesValidation="false" /&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>Login.aspx.cs</p>
  
  <pre><code>    using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using SOME.NAMESPACE.MyApplicationName.WebApplication;
  using SOME.NAMESPACE.MyApplicationName.Bll;
  
  namespace SOME.NAMESPACE.MyApplicationName.WebApplication
  {
      public partial class Login : BasePage
      {
          protected void Page_Load(object sender, EventArgs e)
          {
              Login1.Focus();
          }
          protected void btnCreateAccount_Click(object sender, EventArgs e)
          {
              Page.Response.Redirect("~/CreateUser/default.aspx");
          }
      } 
  }
  </code></pre>
  
  <p>Here is the code for default.aspx and default.aspx.cs which is throwing the parser error when viewed in a web browser:</p>
  
  <p>Default.aspx</p>
  
  <pre><code>    &lt;%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/MainMaster.master" AutoEventWireup="True" Inherits="SOME.NAMESPACE.MyApplicationName.WebApplication._Default" Codebehind="Default.aspx.cs" %&gt;
  &lt;%@ MasterType VirtualPath="~/MasterPages/MainMaster.master" %&gt;
  &lt;asp:Content ID="MainContent" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server"&gt;
  &lt;div class="post"&gt;
      &lt;h2 class="title"&gt;Announcements&lt;/h2&gt;
      &lt;p class="meta"&gt;Posted by Amanda Myer on December 15, 2009 at 10:55 AM&lt;/p&gt;
      &lt;div class="entry"&gt;
          &lt;p&gt;The MyApplicationName CMDB will be down for maintenance from 5:30 PM until 6:30 PM on Wednesday, December 15, 2009.&lt;/p&gt;
      &lt;/div&gt;
      &lt;p class="meta"&gt;Posted by Amanda Myer on December 01, 2009 at 1:23 PM&lt;/p&gt;
      &lt;div class="entry"&gt;
          &lt;p&gt;The MyApplicationName CMDB is officially live and ready for use!&lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="SideBarContent" ContentPlaceHolderID="SideBarPlaceHolder" Runat="Server"&gt;
      &lt;img src="images/MyApplicationName.jpg" alt="MyApplicationName Gremlin" width="250"/&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>Default.aspx.cs</p>
  
  <pre><code>    using System;
  using System.Configuration;
  using System.Data;
  using System.Linq;
  using System.Web;
  using System.Web.Security;
  using System.Web.UI;
  using System.Web.UI.HtmlControls;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Xml.Linq;
  using SOME.NAMESPACE.MyApplicationName.Bll;
  using SOME.NAMESPACE.MyApplicationName.WebApplication;
  
  public partial class _Default : BasePage
  {
      protected void Page_Load(object sender, EventArgs e)
      {
      }
  }
  </code></pre>
  
  <p>Thanks!</p>