C# 网站及;App#U代码工作不正常(#C)
我只是尝试从app_code文件夹调用网站中的方法,但我没有在visualstudio中创建该项目,而是使用了Azure 所有的aspx文件都在/site/wwwroot文件夹中,而我的App_代码文件夹则在所有文件之外 我尝试过使用名称空间调用,其他人刚才说在类属性中更改编译设置,但选项不会出现在类属性下。(我想这是因为我使用Azure创建了这个项目,我不太确定) 下面是我的代码的外观 Scores.aspx.csC# 网站及;App#U代码工作不正常(#C),c#,asp.net,azure,visual-studio-2012,app-code,C#,Asp.net,Azure,Visual Studio 2012,App Code,我只是尝试从app_code文件夹调用网站中的方法,但我没有在visualstudio中创建该项目,而是使用了Azure 所有的aspx文件都在/site/wwwroot文件夹中,而我的App_代码文件夹则在所有文件之外 我尝试过使用名称空间调用,其他人刚才说在类属性中更改编译设置,但选项不会出现在类属性下。(我想这是因为我使用Azure创建了这个项目,我不太确定) 下面是我的代码的外观 Scores.aspx.cs 使用网球; 公共部分课程网站\u wwwroot\u分数:System.Web
使用网球;
公共部分课程网站\u wwwroot\u分数:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
私人名单玩家=null;
players=PlayerDB.GetPlayers();
FillListBox();
}
受保护的void FillListBox()
{
//foreach(玩家中的玩家p)
//{
//添加(p.GetDisplayText());
//}
}
}
PlayerDB.cs(位于应用程序代码文件夹内)
{
公开课播音员
{
公共玩家b()
{
}
公共静态列表GetPlayers()
{
//创建列表
列表玩家=新列表();
//创建XmlReaderSettings对象
XmlReaderSettings设置=新建XmlReaderSettings();
settings.IgnoreWhitespace=true;
settings.IgnoreComments=true;
//创建XmlReader对象
string path=HttpContext.Current.Server.MapPath(“~/site/wwwroot/players.xml”);
XmlReader xmlIn=XmlReader.Create(路径、设置);
//将所有节点读取到第一个播放器节点
xmlIn.ReadToDescendant(“播放器”);
//为每个玩家节点创建一个玩家对象
做
{
玩家p=新玩家();
xmlIn.ReadStartElement(“玩家”);
p、 PlayerNumber=xmlIn.ReadElementContentAsString();
p、 playerTotalSetCore=xmlIn.ReadElementContentAsString();
p、 PlayerTotalWin=xmlIn.ReadElementContentAsString();
玩家。添加(p);
}
而(xmlIn.ReadToNextSibling(“播放器”);
//关闭XmlReader对象
xmlIn.Close();
返回球员;
}
}
}
Visual Studio没有显示任何错误或任何内容,但每当我尝试浏览我的网站时,都会发生运行时错误。对于azure(IIS)中的Web服务器,/site/wwwroot文件夹是网站根路径。包含所有应用程序代码的文件夹,该文件夹之外的任何其他内容都被视为无应用程序代码 查看azure web应用程序的完整文件夹结构(典型) 因此,您的App_代码文件夹在运行时未编译/处理 您应该将应用程序代码文件夹移动到/site/wwwroot/
但是,我的建议——强烈的建议——是您从Visual Studio构建整个解决方案,这可以帮助您避免此类错误,当然还有许多其他错误会让您陷入地狱。尝试使用远程调试来解决此问题。您可以使用远程调试来附加到web应用并对其进行调试()。每当我在VS中查看服务器资源管理器时,我看不到任何web配置文件。每当我通过VS“发生运行时错误”打开网站时,我只会看到web配置文件您需要告诉我们该错误是什么。它只是在“/”应用程序中显示服务器错误,因为我无法启用远程调试。错误消息(称为死亡黄屏或YSOD)解释了如何启用它,以便您可以看到实际的错误消息。遵循这些指示。您必须修改web.config。
using Tennis;
public partial class site_wwwroot_Scores : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
private List<Player> players = null;
players = PlayerDB.GetPlayers();
FillListBox();
}
protected void FillListBox()
{
//foreach (Player p in players)
//{
// lstBxPlayers.Items.Add(p.GetDisplayText());
//}
}
}
namespace Tennis
{
public class PlayerDB
{
public PlayerDB()
{
}
public static List<Player> GetPlayers()
{
// create the list
List<Player> players = new List<Player>();
// create the XmlReaderSettings object
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
// create the XmlReader object
string path = HttpContext.Current.Server.MapPath("~/site/wwwroot/players.xml");
XmlReader xmlIn = XmlReader.Create(path, settings);
// read past all nodes to the first Player node
xmlIn.ReadToDescendant("Player");
// create one Player object for each Player node
do
{
Player p = new Player();
xmlIn.ReadStartElement("Player");
p.PlayerNumber = xmlIn.ReadElementContentAsString();
p.PlayerTotalSetScore = xmlIn.ReadElementContentAsString();
p.PlayerTotalWin = xmlIn.ReadElementContentAsString();
players.Add(p);
}
while (xmlIn.ReadToNextSibling("Player"));
// close the XmlReader object
xmlIn.Close();
return players;
}
}
}