不在独立exe中运行时必须指定exePath [英] exePath must be specified when not running inside a stand alone exe

查看:425
本文介绍了不在独立exe中运行时必须指定exePath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Web应用程序时,下面的代码行

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,但.Net选项卡中的添加引用"没有dll.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆