我在尝试为我的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 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");
但在部署应用程序时,问题仍然存在,因为即使你从文件中加载设置,配置文件夹中其他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
,这两个都在我的应用程序的web.config文件中添加了。