gpt4 book ai didi

c# - 如何修复服务器错误 '/' 应用程序?

转载 作者:太空狗 更新时间:2023-10-30 01:15:10 24 4
gpt4 key购买 nike

我一直在关注这个关于如何使用 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

最佳答案

您的类 Coffee 没有采用 0 参数的构造函数。在 Coffee.cs

中添加以下构造函数
public Coffee()
{
}

关于c# - 如何修复服务器错误 '/' 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39593474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com