简体   繁体   中英

How to read a web.config from .Net Window Application

I'm developing a .NET Framework 4.0 based Windows application.
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.

For this, I tried with encrypting values in app.config but faced an issue with token keys.
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.

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. 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;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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