2

我正在尝试为我的 ASP.NET Web 项目实现 AIML 机器人,但我不断收到此错误:

找不到指定的文件。

源错误:第 31 行:
{

第 32 行:myBot = new Bot();

第 33 行:myBot.loadSettings(@"C:\Users\Public\Documents\SITE\bin\config");

第 34 行:myUser = new User("DefaultUser", this.myBot);

第 35 行:AIMLbot.Utils.AIMLLoader 加载器 = new AIMLbot.Utils.AIMLLoader(this.myBot);

这是我的代码:

protected void Page_Load(object sender, EventArgs e)
{
            myBot = new Bot();
            myBot.loadSettings(@"C:\Users\Public\Documents\SITE\bin\config");
            myUser = new User("DefaultUser", this.myBot);
            AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(this.myBot);
            this.myBot.isAcceptingUserInput = false;
            loader.loadAIML(@"C:\Users\Public\Documents\SITE\bin\aiml");
            this.myBot.isAcceptingUserInput = true;
}

在我看来,在本地主机上运行时找不到配置文件夹?我究竟做错了什么?

4

2 回答 2

1

我知道这是一篇旧帖子,但我正在添加我的解决方案,以防其他人遇到同样的问题。

您的问题是您没有指定设置文件。

试试这样:

 myBot.loadSettings(@"C:\Users\Public\Documents\SITE\bin\config\Settings.xml");

但是在部署应用程序时,问题仍然存在,因为即使您从文件中加载设置,config 文件夹中其他 xml 文件的路径也将相同:

 return Path.Combine(Environment.CurrentDirectory, this.GlobalSettings.grabSetting("configdirectory"));

您可以做的是:您可以添加 config 目录,C:\Windows\System32\inetsrv 也可以下载源代码并修改PathToConfigFiles属性以匹配您的要求,重新构建并再次添加对项目的引用。

我已经像这样修改了属性:

  private string _pathToConfigFiles;
        public string PathToConfigFiles
        {
            get
            {
                return Path.Combine(this._pathToConfigFiles, this.GlobalSettings.grabSetting("configdirectory"));
            }
            set
            {
                this._pathToConfigFiles = value;
            }
        }

当我实例化机器人时,我有:

   Bot myBot = new Bot();
   myBot.PathToConfigFiles = ConfigurationManager.AppSettings["AimlConfigPath"];
   myBot.loadSettings(ConfigurationManager.AppSettings["AimlSettingsPath"]);

“AimlConfigPath”D:\MyProject\bin和“AimlSettingsPath”D:\MyProject\bin\config\Settings.xml都添加到我的应用程序的 web.config 文件中。

于 2015-07-07T12:34:26.967 回答
0

对于任何 Web 项目,一个好的做法是将所有文件包含在项目中并访问这些文件根目录。

  1. 两者都@"C:\Users\Public\Documents\SITE\bin\config"应该@"C:\Users\Public\Documents\SITE\bin\aiml"在项目内部。(如果您的页面位于文件夹中,这只是一个示例)。

在此处输入图像描述

  1. 在 ServerMapPath 中使用波浪号“~”或“../”,您应该到达项目的 ROOT 文件夹,并且访问应该如下所示(例如,我能够使用 File.ReadAllLines("path") 访问该文件)。 在此处输入图像描述
  2. 结果 在此处输入图像描述

*注意:重建/调试时,在重建期间始终将特殊文件设置为“始终复制”,否则在部署 Web 项目时该文件将不存在。 在此处输入图像描述

于 2015-07-07T15:36:01.143 回答