Store program data

P

Piotrekk

Hi everyone.

I would like to ask about good habid, of keeping program data.
I have written in C# Server and Client applications, and now i need to
care about authorization.
What i mean is that Server should allow login only authorized users -
Admin of the server should have good and comfortable acces to
"permitted users list", with opportunity to add or remove entries in a
good way.
Program should also keep info. where to store received files. This is
also the thinkg that might by changed by administrator of the server.

Where and how o keep this informations.
Should i use XML, or create ini file. Where to place this files.
Program directory or somwhere else.
Thank you for your time and advice.
PK
 
G

Guest

Generally speaking, configuration settings such as where to store files are
kept in the app configuration file. If you add an app.config file to your
project, this will be automatically converted / deployed to the build folder
as yourapp.exe.config. You can either use the appSettings section or a custom
config section to read these settings.

Regarding authentication data such as username / password pairs, unless you
have only a small amount of data, the best place to store this is in a
database and create a method that looks this up based on login parameters
supplied by the user.

Theses are not the only ways to store such data, but hopefully they give you
some ideas.
 
P

Piotrekk

Thanks. That's the way i will implement this.
BTW.
I have added config file, as you explained.
It's of the form:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<AppSettings>
<add key="Key1" value="Kevin" />
<add key="Key2" value="150" />
<add key="Key3" value="Rice" />
</AppSettings>
</configuration>

Then i try to receive some keys from xml by:
String ppp =
System.Configuration.ConfigurationSettings.AppSettings["Key1"];

Am i doing something wrong? I found this example on the internet, (
manually added config file ).
Anyway ppp == null
PK
 
G

Guest

The config file must be named "app.config" and be included in your project to
be translated into yourapp.exe.config and placed next to the built executable
after a build or in an F5 debug operation.
you might have to cast values as (string) when pulling them out with the
code you show. Otherwise, I can't see anything wrong with it except for the
fact that your appSettings element has a Capital "A". It needs to read
"appSettings".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top