【问题标题】:Parser Error- is not allowed here because it does not extend class 'System.Web.UI.Page'解析器错误-此处不允许,因为它不扩展类“System.Web.UI.Page”
【发布时间】:2017-04-05 05:27:54
【问题描述】:

我正在学习本教程-https://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/introduction-and-overview

当我到达 AddToCart 的部分时,我尝试运行它并收到此错误 -

Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: 'WingTipToys.AddToCart' is not allowed here because it does not extend class 'System.Web.UI.Page'.

Source Error: 


Line 1:  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddToCart.aspx.cs" Inherits="WingTipToys.AddToCart" %>
Line 2:  
Line 3:  <!DOCTYPE html>

Source File: /AddToCart.aspx    Line: 1 

我应该寻找什么?

这是cs文件-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using WingtipToys.Logic;
namespace WingtipToys
{
    public partial class AddToCart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];
            int productId;
            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId))
            {
                using (ShoppingCartActions usersShoppingCart = new
               ShoppingCartActions())
                {
                    usersShoppingCart.AddToCart(Convert.ToInt16(rawId));
                }
            }
            else
            {
                Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId.");
            throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId.");
            }
            Response.Redirect("ShoppingCart.aspx");
        }
    }
}

【问题讨论】:

  • AddToCart 的类定义是什么?
  • 我添加了cs文件。那是你要找的吗?我刚刚开始学习本教程。

标签: asp.net


【解决方案1】:

我也有这个错误。检查您的 AddToCart.aspx 并检查 Inherits="WingTipToys.AddToCart"。

这实际上应该是“WingtipToys.AddToCart”。我做了那个改变,它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多