2016-09-20 72 views
4

我一直在關注如何使用asp.net建立網站並在MSSQL中連接這個舊的Youtube視頻。由於我還沒有關於如何創建後端的知識,所以我認爲有一個格式要遵循是個好主意。我複製了所有的代碼,最終導致了一些錯誤。我只是點擊了潛在的修補程序並選擇了第一個可用的選項。所有錯誤都消失了,我可以運行網站的主頁。但是當我瀏覽評論和咖啡時。我在'/'應用程序中遇到了服務器錯誤。儘管我想自己解決這個問題,但我現在還沒有任何想法可以改變。希望你們可以幫忙。如何解決服務器錯誤'/'應用程序?

enter image description here

這是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> 

這是CSS代碼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; 
} 

在App_Code文件夾是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; 
    } 
    } 
    } 

此外,在App_Code文件是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; 

    } 
    } 
    } 

順便說一句,這是我的Visual Studio的截圖: enter image description here

而且還數據庫的名字是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 
+0

http://stackoverflow.com/questions/1063190/how-to-resolve-server-error-in-application-error – Techidiot

+0

傢伙FYI,這個問題尚未解決。 – BrunoEarth

回答

4

您的班級Coffee沒有構造函數,其參數爲參數。 添加下面的構造函數中Coffee.cs

public Coffee() 
{ 
} 
+0

我已經在Coffee.cs中添加了構造函數,但它仍然有相同的錯誤。其他解決方案? – BrunoEarth

+0

您的構造函數期望參數,並添加我的構造函數 – xameeramir

+0

我的意思是我添加了您建議的構造函數,並且它仍然存在錯誤。 – BrunoEarth

相關問題