我最近在VisualStudio2008中将一个网站项目转换为一个web应用程序项目.我最终将其编译,第一页(登录屏幕)显示为正常,但当它重定向到默认值时.aspx页面,我收到一个错误:
Parser Error Message: 'SOME.NAMESPACE.MyApplicationName.WebApplication._Default' is not allowed here because it does not extend class 'System.Web.UI.Page'.
我的所有页面都继承自一个名为"BasePage"的类,该类扩展了System.Web.UI.Page.显然,问题不在于该类,因为Login.aspx页面显示没有错误,而且它也继承自该基本页面.
网站上的所有页面,包括登录页面,都是母版页的子页面.
经过一些测试,我确定了是什么导致了错误(尽管我不知道为什么会这样).
在我具有以下标记的所有页面上,都不会出现错误.
<%@ MasterType VirtualPath="~/MasterPages/MainMaster.master" %>
在所有不包含该行的页面上,都会发生错误.这贯穿于整个应用程序.我只有在需要引用母版页控件的页面上才有标签.
所以,我想我应该把这一行添加到我所有的页面中,然后完成它.但当我添加这一行时,我会得到一个编译错误:
这个错误来自与我添加了"MasterType"声明的ASPX页面相关联的signer.cs文件.
我已强制重建设计器文件,但这不会改变任何事情.我比较了设计器文件中主参考的内容和登录名.aspx(工作)和默认值.aspx(不工作),但它们完全一样.
既然我真的想让它工作起来,而不必向每个页面添加"MasterType"声明,既然"fix"无论如何都不起作用,有人知道为什么在aspx文件上没有"MasterType"声明会导致解析器错误吗?有解决办法吗?
示例代码:
这是登录的代码.aspx和登录.aspx.工作正常的cs:
Login.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/MainMaster.master" AutoEventWireup="true" Inherits="SOME.NAMESPACE.MyApplicationName.WebApplication.Login" Codebehind="Login.aspx.cs" %>
<%@ MasterType VirtualPath="~/MasterPages/MainMaster.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
<table>
<tr>
<td>
<asp:UpdatePanel ID="upLogin" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" DefaultButton="Login1$LoginButton">
<asp:Login ID="Login1" runat="server" LoginButtonStyle-CssClass="button"
TextBoxStyle-CssClass="textBoxRequired"
TitleTextStyle-CssClass="loginTitle" >
</asp:Login>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upPasswordRecovery" runat="server">
<ContentTemplate>
<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." />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="SideBarPlaceHolder" Runat="Server">
<h2>Login</h2>
<asp:Button ID="btnCreateAccount" runat="server" Text="Create Account" OnClick="btnCreateAccount_Click" CausesValidation="false" />
</asp:Content>
Login.aspx.cs
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");
}
}
}
以下是在Web浏览器中查看时引发解析器错误的default.aspx和default.aspx.cs的代码:
违约aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/MainMaster.master" AutoEventWireup="True" Inherits="SOME.NAMESPACE.MyApplicationName.WebApplication._Default" Codebehind="违约aspx.cs" %>
<%@ MasterType VirtualPath="~/MasterPages/MainMaster.master" %>
<asp:Content ID="MainContent" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
<div class="post">
<h2 class="title">Announcements</h2>
<p class="meta">Posted by Amanda Myer on December 15, 2009 at 10:55 AM</p>
<div class="entry">
<p>The MyApplicationName CMDB will be down for maintenance from 5:30 PM until 6:30 PM on Wednesday, December 15, 2009.</p>
</div>
<p class="meta">Posted by Amanda Myer on December 01, 2009 at 1:23 PM</p>
<div class="entry">
<p>The MyApplicationName CMDB is officially live and ready for use!</p>
</div>
</div>
</asp:Content>
<asp:Content ID="SideBarContent" ContentPlaceHolderID="SideBarPlaceHolder" Runat="Server">
<img src="images/MyApplicationName.jpg" alt="MyApplicationName Gremlin" width="250"/>
</asp:Content>
违约aspx.cs
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)
{
}
}
谢谢