不在独立 exe 中运行时必须指定 exePath [英] exePath must be specified when not running inside a stand alone exe
本文介绍了不在独立 exe 中运行时必须指定 exePath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用网络应用程序时,下面的代码行
When i am using a web application, the line of code below
Configuration objConfig =
ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None);
在类库中出现此错误:
当不在独立 exe 中运行时,必须指定 exePath."
"exePath must be specified when not running inside a stand alone exe."
以前使用的是控制台应用程序,代码可以访问app.config
.我尝试在类库中使用 System.Web.Configuration
但 dll 不存在于添加引用"的 .Net 选项卡中.
Previously a console application was being used, and the code could access the app.config
. I tried using the System.Web.Configuration
in class library but the dll was not present in the .Net tab for "Add reference".
请帮助:)
推荐答案
您需要在 Web 上下文中使用不同的配置管理器.以下代码块显示了如何处理此问题的示例:
You need to use a different configuration manager in a web context. The following code block shows an example of how to deal with this:
System.Configuration.Configuration configuration = null;
if (System.Web.HttpContext.Current != null)
{
configuration =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
}
else
{
configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
}
这篇关于不在独立 exe 中运行时必须指定 exePath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文