?
在自己的ActionServlet.DLL[C#]中尝试用ApplicationHost
直接执行aspx文件,而不用IIS。
结果耗费了两个小时在一个小问题上,痛心疾首啊!
?
我的代码如下:
private static HostRequest m_Host; 。。。 m_Host = (HostRequest)ApplicationHost.CreateApplicationHost( ???????????????????????????????????????????????? typeof(HostRequest), ?????? ????????????????????????????????????????? "/foo", ???????????????????????????????????????????????? // |
?
然后在本目录下放置一个aspx文件。
然而,蹊跷的事情来了。
我在一个UsingAspRuntime工程目录下运行测试程序,可以正常创建这个ApplicationHost。
在其他目录下,却无法创建!一到这里就发生异常System.IO.FileNotFoundException,其错误内容为:
“File or assembly name ActionServlet, or one of its dependencies, was not found.”
(“找不到文件或程序集名称“ActionServlet”,或找不到它的一个依赖项”)
?
没有搞清楚原理之前,我真的被这个错误描述搞晕了,一心想看出UsingAspRuntime工程目录到底有什么不同寻常之处,难道是权限?难道和Cache有关?难道和machine.config有关?
?
终于,在google新闻组上翻阅上百篇文献后,看到了这句话:
“You have to create a bin directory as subdirectory to your current directory and move a copy of ConsoleHost.exe to it. Now you have two copies of ConsoleHost.exe, one in the current directory (in my case f:/temp/test/) and another in /bin (in my case f:/temp/test/bin) directory. ”
?
真是醍醐灌顶。
原来就是,你试图创建的那个物理路径下,必须有一个子文件夹bin,其中放置你的运行所依赖的那些组件!
我把ActionServlet.dll放进去,就一切正常了!
哎,如果早知道了CreateApplicationHost背后的原理,我岂不是能走弯路两个小时?!
?
参考文档:
http://www.csharphelp.com/archives/archive248.html
《Processing A .aspx File From Console Window, Without Using IIS
By Jamsheer E B》
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=60156