Active Server Pages Programming (ASP)/global variables for asp.net

Advertisement


Question
QUESTION: Hello,
Where do I define or initialize a session variable, or any other global variable for that matter in an asp.net project? In ASP there was a global.asa page there by default. I don't know what's used in ASP.Net. Could you please help? Thank you SO much!
Heidi

ANSWER: Hi

it stores in web.config file.  for storing database connection string and other info

something like this

<appSettings>
  <add key="MyName" value="Srini" />
</appSettings>


in the code

string MyName=ConfigurationSettings.AppSettings["MyName"];


Check for more info.

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=106


-srini


---------- FOLLOW-UP ----------

QUESTION: Thank you. I found that I can add a global application class called global.asax. What's the difference between web.config and global.asax? Which one do you suggest I use for storing session variables, connection strings , and any other global variable? Thanks again!!! :-)

Answer
Hi,

You set all your connection and other constant variables in web.config, all session settings  you can use global.asax.

web.config is an xml configuration file that the application loads when it starts.

global.asax is a class file, it holds the Global application class and its intrinsic methods (e.g., Application_Start ,etc) plus whatever other fields
and methods you want to add there.


-Srini

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.

©2012 About.com, a part of The New York Times Company. All rights reserved.