Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

c# - create your own settings in xml

I'm in a ASP.NET project where I need to give several parameters to the administrator that is going to install the website, like:

AllowUserToChangePanelLayout
AllowUserToDeleteCompany

etc...

My question is, will be a good thing to add this into the web.config file, using my own configSession or add as a profile varibles? or should I create a XML file for this?

What do you do and what are the cons and favs?

I originally thought about web.config but I then realized that I should mess up with Website configurations and my own web app configuration and that I should create a different file, them I read this post and now I'm on this place... should I do this or that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I usually use Settings - available via the project properties - Settings. These can be edited and saved in code, and I write a form / web page to edit them.

If you want to use the XML configuration, there's an attribute called file that reads external files. You could have a web.config file and a someothername.config file. The someothername.config would have settings like:

<appSettings>
    <add key="ConnString" value="my conn string" />
    <add key="MaxUsers" value="50" />
</appSettings>

And the web.config would have

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings file="ExternalWeb.config">
        <add key="MyKey" value="MyValue" />
    </appSettings>
</configuration>

See DevX for the example I stole.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...