Get a global value for the web applicetion

JustAskMe
JustAskMe used Ask the Experts™
on
I have a internet store asp.net application I use the same application under a few domain names but the database is the same, and the back end admin application is the same too.

Now I want to set a lot of settings that should be specific to the domain the applicetion is runing under, (I mean it can't be excitedly the same :)) so I want to know what the easy-es way to do it.

I want to be able to set in "one" place in the application the name or ID of this site, and be able to refrance it from all over the place.

any idea?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sr. System Analyst
Commented:
put a setting into web.config
domainname = domain1
for example
and create some tables in db

domains(did, domain)
settings(sid, sname, description)
settingValues(sid,did, value) you can add languageid here if you want values change depending on current language too...

and connect to this db, using the values from web confog to get the desired value
HainKurtSr. System Analyst

Commented:
for example create sp's

getAllSettings(domain)
getAllSettingsByDID(did)
getSetting(domain, setting)
getSettingByDID(did, setting)

or to simplify, you can add domainid into the web.config and just use did to get values

getAllSettingsByDID(did)
getSettingByDID(did, setting)

Author

Commented:
Thanks for your heLp, but I need to reference this in C# code to pass in to my SP.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

HainKurtSr. System Analyst
Commented:
dim domain as string = System.Configuration.ConfigurationManager.AppSettings("domain")
dim did as integer =  System.Configuration.ConfigurationManager.AppSettings("did")

Another option would be to add a .resx file into your App_GlobalResources folder, this is then available in a convenient manner throughout your program.  It is generally used for localization, but also very useful for storing global vairables.

For example, if you make a 'Common.resx' file and add a value named 'Domain' with the value 'MyDomain', you can now reference it from anywhere with this:
string domain = Resources.Common.Domain;
 
// since it is in the App_GlobalResources folder, it is automatically 
// made into a class of the Resources class, with properties that 
// directly reflect the ones you enter

Open in new window

alternatively, you could make your own resource type static class in your App_Code folder, something like this:
public static class MyResources
{
  public static string Domain { get { return "MyDomain"; } }
}
 
//now you can call it form anywhere:
string domain = MyResources.Domain;

Open in new window

Author

Commented:
Thanks for all the help,

Now I want to know if its also possible to add the domain directly to the SP?

that means that I want the SP to look up the web.config or the Resources file.

Is that possible?
well, not really directly from the SQL, but if you are doing it through asp.net sure, for example, if you are using LINQ
yourDataContext.SomeTable.StoreProcedure(MySettings.Domain);

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial