Get variables from web.config and global.asax

Saturday, December 5, 2009

There are two methods, you can assign variable at one place and call it from through out the website.

The first is, Declare the variable in web.config and call it in any aspx.cs page and the second is, Declare the variable in global.asax and call it in any aspx.cs page.

The first one is very usefull because you can edit it directly form the FTP editor.

Please find explanation and code of both method below,

First Method:
<add key="siteurl" value=""/>
<add key="TempDir" value="./uploads"/>


Second Method:
void Session_Start(object sender, EventArgs e)
// Code that runs when a new session is started
Application["siteurl"] = "";
Application["TempDir"] = "./uploads";

string smtphost = Application["siteurl"].ToString();
string userid = Application["TempDir"].ToString();

Please use any of the above method which is needed in your application.

Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)

No comments :