【发布时间】:2016-03-15 11:43:51
【问题描述】:
我只是想从 app_code 文件夹调用网站中的方法,但我没有在 Visual Studio 中创建项目,我使用的是 Azure。
所有的 aspx 文件都在 /site/wwwroot 文件夹中,而我的 App_Code 文件夹在一切之外。
我尝试过使用命名空间调用,而其他人刚刚说过更改类属性中的编译设置,但该选项不会出现在类属性下。 (我认为是因为我使用 Azure 创建的项目,我不太确定)
这是我的代码看起来正确的样子。
Scores.aspx.cs
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());
//}
}
}
PlayerDB.cs(位于 App_Code 文件夹内)
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;
}
}
}
Visual Studio 没有显示任何错误或任何内容,但每当我尝试浏览我的网站时,都会出现运行时错误。
【问题讨论】:
-
尝试使用远程调试来发现问题。您可以使用远程调试附加到您的 Web 应用程序并对其进行调试 (azure.microsoft.com/en-us/documentation/articles/…)。
-
每当我在 VS 中查看服务器资源管理器时,我都看不到 Web 配置文件,每当我通过 VS 打开网站时,我只看到一个 Web 配置文件
-
“出现运行时错误”您需要告诉我们该错误是什么。
-
它只是说“/”应用程序中的服务器错误,因为我无法启用远程调试
-
错误消息(称为黄屏死机或 YSOD)解释了如何启用它,以便您可以看到实际的错误消息。遵循这些指示。您必须修改 web.config。
标签: c# asp.net azure visual-studio-2012 app-code