Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store configuration settings outside of web.config

Tags:

c#

asp.net

I'm starting to consider creating a class library that I want to make generic so others can use it. While planning it out, I came to thinking about the various configuration settings that I would need. Since the idea is to make it open/shared, I wanted to make things as easy on the end user as possible. What's the best way to setup configuration settings without making use of web.config/app.config?

like image 661
Wil Avatar asked Jun 06 '10 22:06

Wil


People also ask

Can we run application without web config?

An application can execute without a web. config file, however, you cannot debug an application without a web. config file.

Where do I put appSettings in web config?

Locate the web. config file in the root directory of your application (or create one if it does not already exist). Add an <appSettings> element. Add <add> child elements along with key / value pairs to the <appSettings> element as required.

Is Web config file sensitive?

Web. config files may contain sensitive data. To better protect this data and strengthen the security of SharePoint, SharePoint now restricts access to its Web.

How many Web config files can I have in an solution?

Yes you can have two web. config files in application.


2 Answers

Why are you rejecting the use of web.config/app.config? That's what they're for, and that's totally the way I'd do it.

Put an example block of code for the web.config/app.config in your documantation that could be copy-and-pasted into the real config file. If documented well, it shouldn't really be a problem for your users.

Just be sure you don't crash because the settings don't exist. Or, if you do crash, give a detailed error message telling the user to edit the proper config file and where in the documentation they can find examples. That would make it easier on your user.

like image 106
BoltBait Avatar answered Oct 31 '22 05:10

BoltBait


I think it's not wrong to use the web.config for storing you configuration items. But you could be more flexible offering 3 configuration options as many popular libraries do (nhibernate, log4net, etc)

  • Use Web.config
  • Use a external xml file
  • Configure library programatically

Doing it like this you leave the decision on your library users instead of supposing they won't be happy using the web.config.

like image 26
Claudio Redi Avatar answered Oct 31 '22 05:10

Claudio Redi