I am working through this tutorial- https://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/introduction-and-overview
When I get to the part to AddToCart I try to run it and get this error-
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
What should I look for?
This is the cs file-
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");
}
}
}
I had this error as well. Check your AddToCart.aspx and check the Inherits="WingTipToys.AddToCart".
This should actually be "WingtipToys.AddToCart". I made that change and it worked for me.