Pra*_*pta 30 c# app-config web-config
当我使用Web应用程序时,下面的代码行
Configuration objConfig =
ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None);
Run Code Online (Sandbox Code Playgroud)
在类库中给出了这个错误:
"当不在独立的exe内部运行时,必须指定exePath."
以前正在使用控制台应用程序,代码可以访问app.config.我尝试使用System.Web.Configuration类库,但是.Net选项卡中没有"添加引用"的dll.
请帮助:)
小智 48
您需要在Web上下文中使用其他配置管理器.以下代码块显示了如何处理此问题的示例:
System.Configuration.Configuration configuration = null;
if (System.Web.HttpContext.Current != null)
{
configuration =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
}
else
{
configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
}
Run Code Online (Sandbox Code Playgroud)
小智 2
我不确定你在做什么;但乍一看,您似乎正在尝试在 Web 环境中使用为 WinForms 应用程序编写的代码。这几乎肯定行不通,因为您的网络应用程序没有您需要的权限。
尝试查找如何在 Web 环境中执行此操作(因为您似乎正在处理配置文件,所以尝试在 WEB.CONFIG 上搜索以开始)
| 归档时间: |
|
| 查看次数: |
14587 次 |
| 最近记录: |