【问题标题】:Website & App_Code not working correctly (#C)网站和 App_Code 无法正常工作 (#C)
【发布时间】: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


【解决方案1】:

对于 azure (IIS) 中的网络服务器,/site/wwwroot 文件夹是网站根路径。包含所有应用程序代码的文件夹,该文件夹之外的任何其他内容均视为无应用程序代码。

查看 azure web 应用程序的完整文件夹结构(典型)

因为您的 App_Code 文件夹在运行时未编译/处理。

您应该将 App_Code 文件夹移动到 /site/wwwroot/

但是,我的建议 - 强烈建议 - 是您从 Visual Studio 构建您的整个解决方案,这可以帮助您避免此类错误,并且肯定会避免许多其他可能让您陷入困境的错误。

【讨论】:

    猜你喜欢
    • 2018-02-17
    • 2022-01-18
    • 2016-09-14
    • 2017-12-03
    • 2018-10-13
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2022-11-13
    相关资源
    最近更新 更多