简体   繁体   English

如何从.Net Window应用程序中读取web.config

[英]How to read a web.config from .Net Window Application

I'm developing a .NET Framework 4.0 based Windows application. 我正在开发基于.NET Framework 4.0的Windows应用程序。
I have a requirement of distributing this window application, along with source code to client. 我需要将此窗口应用程序以及源代码分发给客户端。

When I test I'm using my own database credentials. 当我测试我使用自己的数据库凭据时。
So I want a method to somehow hide the app.config details. 所以我想要一种方法以某种方式隐藏app.config细节。

For this, I tried with encrypting values in app.config but faced an issue with token keys. 为此,我尝试在app.config中加密值,但遇到令牌密钥问题。
While researching about it, I found that I can use: 在研究它时,我发现我可以使用:

System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration. 

But that again required username and password for accessing remote server and don't want to show them to the client. 但是,这又需要用户名和密码来访问远程服务器,并且不希望将它们显示给客户端。

So for this I planned to read web.config hosted on IIS 7.5 Server. 因此,我计划阅读IIS 7.5 Server上托管的web.config。

Could you please help me in that context? 在这方面你能帮我吗?
Or if you have better ideas to achieve the objective, do share. 或者,如果您有更好的想法来实现目标,请分享。

The code is designed to be very close in syntax to the usual method used for accessing web.config from a web app. 该代码的设计与用于从Web应用程序访问web.config的常用方法的语法非常接近。 Pass the constructor the location of the web.config file you wish to parse and then use the AppSettings method to obtain the desired value; 将构造函数传递给要解析的web.config文件的位置,然后使用AppSettings方法获取所需的值;

string filename = @"c:\temp\Web.Config"; 
UK.Org.Webman.ConfigurationSettings ConfigurationSettings = 
    new UK.Org.Webman.ConfigurationSettings(filename); 
string PrimaryDatabase = ConfigurationSettings.AppSettings["PrimaryDatabase"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM