我正在尝试为我的 ASP.NET Web 项目实现 AIML 机器人,但我不断收到此错误:
Unable to find the specified file.
Source Error: Line 31:
{Line 32: myBot = new Bot();
Line 33: myBot.loadSettings(@"C:\Users\Public\Documents\SITE\bin\config");
Line 34: myUser = new User("DefaultUser", this.myBot);
Line 35: AIMLbot.Utils.AIMLLoader loader = 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;
}
我觉得它在本地主机上运行时找不到配置文件夹?我做错了什么?
最佳答案
我知道这是一篇旧帖子,但我正在添加我的解决方案,以防其他人遇到同样的问题。
您的问题是您没有指定设置文件。
像这样尝试:
myBot.loadSettings(@"C:\Users\Public\Documents\SITE\bin\config\Settings.xml");
但是在部署应用程序时,问题仍然存在,因为即使您从文件中加载设置,config 文件夹中其他 xml 文件的路径也是相同的:
return Path.Combine(Environment.CurrentDirectory, this.GlobalSettings.grabSetting("configdirectory"));
您可以做的是:
您可以在 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
都添加在网络中我的应用程序的 .config 文件。
关于c# - ASP.NET 项目中的 AIML Bot 无法找到 CONFIG 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28808067/