How to deal with constants?

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Running asp.net 2.0

I have never used global constants and I am a bit confused on the
subject.

I want to give the admin of an application a lot of control over
display.

i.e. custom error messages, number of rows displayed, etc.

Assuming that all these 'constants' are stored in a database table,
what is the best way of incorporating them into the application?

Should I used global.asax, i.e. make a call to the database, loop
through the values and declare them as constants? If so, can somebody
give me a few lines of code as an example? Are there any better ways?
 
Contants IN DB ???
Nahh.

Just create a class like class1
Public Const Hello As String = "hello"

then access it through: class1.Hello
No need to create a class instance.

Public functions:
Public Shared Function....
No need to create a class instance.
 
Assuming that all these 'constants' are stored in a database table,
what is the best way of incorporating them into the application?

How "constant" are they? Do they change never, occasionally, sometimes,
quite often, all the time...?
Should I used global.asax, i.e. make a call to the database, loop
through the values and declare them as constants? If so, can somebody
give me a few lines of code as an example? Are there any better ways?

Whenever I have a smallish amount of static data which is accessed lots of
times in the web app, I tend to read it into a Hashtable in the
Application_Start event and thereafter read it from there rather than
constantly querying the database for the same piece of data over and over
again.

A good example of this are countries and currencies. They hardly ever
change, so it doesn't make sense to keep looking them up...
 
Hi Steve,

We use Enterprise Library 2005's configuration application block. It enables
you to store all application specific configuration information in a config
file (separate from the web.config to keep it from becoming messy) and
allows you to use a generic API provided by the configuration block to read
back values. The Enterprise Library 2005 comes with a configuration tool to
enable your application admin to modify the config files. This article
http://weblogs.asp.net/pgielens/archive/2005/05/16/406911.aspx explains how
to do this.

EntLib 2005
http://www.microsoft.com/downloads/...09-660E-444E-945A-6B32AF1581B3&displaylang=en

Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/
###
 
I like this idea, but I don't want a non-tech admin editing a .vb file,
that's why I am think of using a database which can be updated online.
 
I like this idea, but I don't want a non-tech admin editing a .vb file,
that's why I am think of using a database which can be updated online.
 
That's really not necessary.
A simple resource text file could do.
I assume IIS/.NET will recompile resources as well when they are changed.

So a simple dummy-must-fill text file could do.
You simply drop the file once on a resource.rex (whatever it's name) part
and you are ready.
 

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

Back
Top