asp.net - 尝试在浏览器中预览 ASPX 文件时出现解析器错误和/或编译器错误
问题描述
我目前正在学习 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;
}
}
}
我为糟糕的格式道歉,我在这里看到过类似的问题,但答案没有产生任何结果,我对此也很陌生,所以我很确定我可能误解了以前的答案。
解决方案
将带有命名空间的页面放在 .aspx 中的 inherts-property 中,如 Inherits="website05.Default",此处不要使用 BasePage。
推荐阅读
- css - 如何在 Angular 7 应用程序中共享 LESS 或 CSS 文件?
- javascript - 将 e.location 字符串拆分为变量
- types - Ocaml 用户定义类型和函数
- python - 尝试使用 \t 执行多个选项卡
- javascript - 使用 Chrome 扩展程序更改选项时在选择元素上触发事件
- google-cloud-platform - Big Query - 阻止本地文件上传
- python - 将一系列 str 转换为日期
- azure-devops - 在 Azure Devops 中自动标记 PR 构建
- google-cloud-platform - Cloud SQL 和 HTTP 负载平衡
- javascript - 是否可以使用 React 中的 useState() 钩子在组件之间共享状态?