【问题标题】:Getting Parser error and/or Compiler error when trying to preview ASPX file in browser尝试在浏览器中预览 ASPX 文件时出现解析器错误和/或编译器错误
【发布时间】:2020-05-19 05:59:08
【问题描述】:

我目前正在学习 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)
    {
    }
 {
{

BasePage.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;
    }
}
}

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

【问题讨论】:

  • 你能在 VS 的设计视图中看到预览吗?
  • 是的,我可以在设计视图中进行预览,但是因为我现在正在进行有关用户主题的练习,所以我需要能够在浏览器中查看它。
  • 把你的页面和namespace放在.aspx的inherts-property中,比如Inherits="website05.Default",这里不要使用BasePage。
  • 谢谢,问题解决了。
  • @Eyclonus : 如果解决了这个问题,请标记答案

标签: asp.net master-pages


【解决方案1】:

把你的页面的命名空间放在.aspx的inherts-property中,比如Inherits="website05.Default",这里不要使用BasePage。

【讨论】:

    猜你喜欢
    • 2013-02-06
    • 1970-01-01
    • 2022-01-20
    • 2011-08-31
    • 2023-04-02
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    相关资源
    最近更新 更多