Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Server Error '/' Application?

I've been following this old Youtube video on how to build a website using asp.net and also connecting in MSSQL. Since I have no knowledge yet on how to create back-end stuff, I think it was a good idea to have a format to follow. I copied every code and I ended up having a couple of errors. I just clicked the show potential fixes and chose the first available option. All errors was gone and I was able to run the homepage of the website. But as I navigate through Reviews and then Coffee. I got a Server Error in '/' Application. As much as i want to fix this myself, I don't really have any idea yet on what to change. Hope you can guys help.

enter image description here

This is the Masterpage.Master:

    <%@ Master Language="C#" AutoEventWireup="true"     CodeBehind="Masterpage.master.cs" Inherits="WebApplication1.Masterpage" %>

 <!DOCTYPE html>

 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
<title>My Website</title>
<script  src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
    function mainmenu() {
        $(" #nav ul ").css({ display: "none" });

        $(" #nav li ").hover(function() {
            $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show(400);
        }
        , function() {
            $(this).find('ul:first').css({ visibility: "hidden" });
        });
    }

    $(document).ready(function () {
        mainmenu();
    });
</script>
<link rel="stylesheet" type="text/css" href="~/Styles/Stylesheet.css" />

 </head>
 <body>
<form id="form1" runat="server">
    <div id="wrapper">
        <div id="banner">

        </div>

        <div id="navigation">
            <ul id="nav">
                <li><a href="~/Pages/Home.aspx">Home</a></li>
                <li><a href="#">Reviews</a>
                    <ul>
                        <li><a href="~/Pages/Coffee.aspx"    runat="server">Coffee</a></li>
                        <li><a href="#">Coffee Shops</a></li>
                        <li><a href="#">Coffee Brands</a></li>
                    </ul>
                </li>
                <li><a href="#">Shop</a></li>
                <li><a href="#">About</a></li>
            </ul>
        </div>

        <div id="content_area">

            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>

        </div>

        <div id="sidebar">

        </div>

        <div id="footer">
            <p>All rights reserved</p>
        </div>
    </div>
  </form>
  </body>
  </html>

This is the css code StyleSheet.css:

body 
{
font-family: 'lucida grande' ,Tahoma,Verdana,Arial,sans-serif;
background-color: #e9e9e9;
}

#wrapper 
{
width: 1080px;
margin: 0 auto;
padding: 10px;
border: 5px solid #dedede;
background-color: #fff;
}

#banner 
{
height: 200px;
border: 3px solid #E3E3E3;
background-image: url(../Images/banner.jpg);
background-repeat: no-repeat;
background-size: cover;
}

#navigation 
{
height: 60px;
border: 3px solid #E3E3E3;
margin-top: 20px;
margin-left: 5px;
margin-right: 5px;
background-image: url(../Images/bar_background.png);
text-shadow: 0.1em 0.1em #333;
}

#nav 
{
list-style: none;
}

#nav ul 
{
list-style: none;
margin: 0;
padding: 0;
width: auto;
display: none;
}

#nav li 
{
font-size: 24px;
float: left;
position: relative;
width: 180px;
height: 50px;
}

#nav li ul li 
{
background-image: url(../Images/bar_background.png);
background-repeat: no-repeat;
background-size: cover;
border: 3px solid #E3E3E3;
padding-left: 10px;
}

#nav a:link, #nav a:active, #nav a:visited
{
display: block;
color: #fff;
 text-decoration: none;   
}

#nav a:hover
{
color: lightblue;
}


#content_area  
{
float: left;
width: 750px;
margin: 20px 0 20px 0;
padding: 10px;
border: 3px solid #E3E3E3;
}

#sidebar 
{
float: right;
width: 250px;
height: 400px;
margin: 20px 10px 20px 10px;
border: 3px solid #E3E3E3;
}

#footer 
{
clear: both;
width: auto;
height: 40px;
margin-top: 20px;
background-image: url(../Images/bar_background.png);
text-shadow: 0.1em 0.1em #333;
color: #fff;
text-align: center;
}

 .imgLeft 
{
float: left;
width: 240px;
height: 150px;
margin: 0px 10px 10px 0px;
padding: 10px;
}

.imgRight 
{
float: right;
width: 200px;
height: 250px;
margin: 0px 0px 10px 10px;
padding: 10px;
}

.coffeeTable 
{
width: 750px;
height: 250px;
margin: 10px 10px 10px 0px;
border: 3px solid #E3E3E3;
border-radius: 10px;
}

.coffeeTable tr th, .coffeeTable tr td 
{
text-align: left;
padding: 0px 5px 0px 5px;
}

.coffeeTable img 
{
padding: 0px 10px 10px 10px;
height: 150px;
width: 150px;
}

Under App_Code folder is Coffee.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace WebApplication1.App_Code
    {
    public class Coffee
    {
    public int id { get; set; }
    public string name { get; set; }
    public string type { get; set; }
    public double price { get; set; }
    public string roast { get; set; }
    public string country { get; set; }
    public string image { get; set; }
    public string review { get; set; }

    public Coffee(int id, string name, string type, double price, string roast, string country, string image, string review)
    {
        this.id = id;
        this.name = name;
        this.type = type;
        this.price = price;
        this.roast = roast;
        this.country = country;
        this.image = image;
        this.review = review;
    }
    }
    }

Also, under App_Code is ConnectionClass.cs:

   using System;
   using System.Collections;
   using System.Collections.Generic;
   using System.Configuration;
   using System.Data.SqlClient;
    using System.Linq;
    using System.Web;
    using WebApplication1.App_Code;
    using WebApplication1.Pages;

     namespace WebApplication1.App_Code
     {
      public static class ConnectionClass
       {
        private static SqlConnection conn;
        private static SqlCommand command;

        static ConnectionClass()
        {
        string connectionString = ConfigurationManager.ConnectionStrings["coffeeConnection"].ToString();
        conn = new SqlConnection(connectionString);
        command = new SqlCommand("",conn);
        }

        public static ArrayList GetCoffeeByType(string coffeeType)
        {
        ArrayList list = new ArrayList();
        string query = string.Format("SELECT * FROM coffee WHERE type LIKE   '{0}'",coffeeType);

        try
        {
            conn.Open();
            command.CommandText = query;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                int id = reader.GetInt32(0);
                string name = reader.GetString(1);
                string type = reader.GetString(2);
                double price = reader.GetDouble(3);
                string roast = reader.GetString(4);
                string country = reader.GetString(5);
                string image = reader.GetString(6);
                string review = reader.GetString(7);

                Coffee coffee = new Coffee(id,name,type,price,roast,country,image,review);
                list.Add(coffee);
            }
        }
        finally
        {
            conn.Close();
        }

        return list;

    }
    }
    }

By the way, this is a screenshot of my visual studio: enter image description here

And also name of the database is CoffeeDB:

/****** Object:  Table [dbo].[coffee]    Script Date: 02/09/2014 22:06:18     ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  SET ANSI_PADDING ON
  GO
  CREATE TABLE [dbo].[coffee](
 [id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NOT NULL,
[type] [varchar](50) NOT NULL,
[price] [float] NOT NULL,
[roast] [varchar](50) NOT NULL,
[country] [varchar](50) NOT NULL,
[image] [varchar](255) NULL,
[review] [text] NOT NULL,
 PRIMARY KEY CLUSTERED 
 (
  [id] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY =     OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
   ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
   GO
   SET ANSI_PADDING OFF
   GO
   SET IDENTITY_INSERT [dbo].[coffee] ON
   INSERT [dbo].[coffee] ([id], [name], [type], [price], [roast], [country],    [image], [review]) VALUES (1, N'Caf?au Lait', N'Classic', 2.25, N'Medium',    N'France', N'../Images/Coffee/Cafe-Au-Lait.jpg', N'A coffee beverage consisting    strong or bold coffee (sometimes espresso) mixed with scalded milk in    approximately a 1:1 ratio.')
   INSERT [dbo].[coffee] ([id], [name], [type], [price], [roast], [country],    [image], [review]) VALUES (2, N'Caff?Americano', N'Espresso', 2.25, N'Medium',    N'Italy', N'../Images/coffee/caffe_americano.jpg', N'Similar in strength and    taste to American-style brewed coffee, there are subtle differences achieved by    pulling a fresh shot of espresso for the beverage base.')
   INSERT [dbo].[coffee] ([id], [name], [type], [price], [roast], [country],    [image], [review]) VALUES (3, N'Peppermint White Chocolate Mocha', N'Espresso',    3.25, N'Medium', N'Italy', N'../Images/coffee/white-chocolate-peppermint-   mocha.jpg', N'Espresso with white chocolate and peppermint flavored syrups.
   Topped with sweetened whipped cream and dark chocolate curls.')
   INSERT [dbo].[coffee] ([id], [name], [type], [price], [roast], [country],    [image], [review]) VALUES (4, N'Irish Coffee', N'Alcoholic', 2.25, N'Dark',    N'Ireland', N'../Images/coffee/irish coffee.jpg', N'A cocktail consisting of hot    coffee, Irish whiskey, and sugar, stirred, and topped with thick cream. The     coffee is drunk through the cream.')
   SET IDENTITY_INSERT [dbo].[coffee] OFF
like image 575
BrunoEarth Avatar asked Sep 20 '16 11:09

BrunoEarth


1 Answers

Your class Coffee doesn't have a constructor which takes 0 parameters. Add the below constructor inside Coffee.cs

public Coffee()
{
}
like image 91
xameeramir Avatar answered Sep 30 '22 05:09

xameeramir