尝试在浏览器中预览ASPX文件时出现解析器错误和/或编译器错误

问题描述 投票:0回答:1

我目前正在学习ASP,并且正在解决与母版页继承有关的问题,这使我无法在浏览器中预览页面,VS 2017的设计视图将我限制为仅静态预览。我不是要你写全部内容,但是我无法掌握我在哪里犯了错误,或者我遵循的说明是否有错误。当我将其保留为CodeBehind时,得到:

"Parser Error: BasePage' is not allowed here because it does not extend class 'System.Web.UI.Page" 

如果将其更改为CodeFile,我会得到这个:

"Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)."

这是Default.aspx最重要的事情

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/MasterPages/Frontend.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default.BasePage" %>

Default.aspx.cs看起来像这样:

   namespace website05 
    {
public partial class Default : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 {
{

BaseBase.cs也是这个文件:

   namespace website05
{
    public class BasePage : System.Web.UI.Page
{

    private void Page_PreRender(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(this.Title) || this.Title.Equals("Untitled Page", StringComparison.CurrentCultureIgnoreCase))
        {
            throw new Exception("Page title cannot be \"Untitled Page\" or an empty string.");
        }
    }


    public BasePage()
    {
        this.PreRender += Page_PreRender;
    }
}
}

我为格式不正确而道歉,我在这里看到过类似的问题,但是答案没有产生任何结果,对此我也很陌生,所以我很确定自己可能对以前的答案有误解。] >

我目前正在学习ASP,并且在与母版页继承有关的问题上苦苦挣扎,这使我无法在浏览器中预览页面,VS 2017的设计视图将我限制为...]]] >>

将带有名称空间的页面放在.aspx的inherts-property中,例如Inherits =“ website05.Default”,请不要在此处使用BasePage。

asp.net master-pages
1个回答
0
投票

将带有名称空间的页面放在.aspx的inherts-property中,例如Inherits =“ website05.Default”,请不要在此处使用BasePage。

© www.soinside.com 2019 - 2024. All rights reserved.