Divi WordPress Theme

Topic: Web Application Setting in ASP.NET: Global.asax  (Read 10686 times)

Offline Tech

  • Junior Guru
  • **
  • Posts: 183
  • iTrader: +2/-0
    • View Profile
Web Application Setting in ASP.NET: Global.asax
« on: August 30, 2007, 02:15:54 AM »
Storing the settings of your ASP.NET application in the Global.asax file is the easiest way. This solution is based on using the Application_Start method and global property Application. The Application property of HttpContext class returns HttpApplicationState object for the current HTTP request. HttpApplicationState object allows sharing of global parameters between multiple sessions and requests with you ASP.NET application.

A single instance of an HttpApplicationState class is created the first time a client requests any URL resource from within a particular ASP.NET application virtual directory. A separate single instance is created for each ASP.NET application on a Web server. A reference to each instance is then exposed via the intrinsic HttpContext.Application object.

Method Application_Start occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request.

Review the following example:
Global.asax.cs

protected void Application_Start(Object sender, EventArgs e) {
Application["DbUser"]="dbUser";
Application["DbUserPass"]="myPass";
Application["DbName"]="coolDB";
Application["DbServer"]="my.office.db.server";


string myConnString = "Data Source=" +
Application["DbServer"] + ";Initial Catalog=" +
Application["DbName"] + ";User ID=" +
Application["DbUser"] + ";Password=" +
Application["DbUserPass"];
Application["ConnString"] = myConnString; }

Thus when your web application starts the Application object will contain the values of your parameters and you can access them on page within your application.


SomePage.asax.cs

private void Page_Load(object sender, System.EventArgs e) {
SqlConnection myCnn;
SqlCommand myCmd;
SqlDataReader myReader;
myCnn = new SqlConnection((string)Application["ConnString"]);
myCmd = new SqlCommand("select * from countries", myCnn);
myCnn.Open();
myReader = myCmd.ExecuteReader();
// :
// Do something
// :
myCnn.Close(); }

Let's consider the advantages and disadvantages of using Global.asax as storage for web application parameters. Advantages:

Simplicity of realization You can store the critical parameters, which you don't want to be changed without your confirmation (Developer Name, License Information). The changing of any parameter within Global.asax file requires recompilation of whole application. So it will be impossible to do without an access to source code Disadvantages:

To change the value of any parameter it is required to recompile whole application. Therefore this method is not good for parameters, which have to be changed frequently. Uploading of recompiled version will cause restart of whole application.

http://www.components4u.net

Article Source: http://EzineArticles.com/?expert=Sergey_Turin
« Last Edit: January 01, 1970, 05:30:00 AM by Tech »
VPS Hosting - AccuWebHosting

Offline jonyroger

  • Newbie
  • *
  • Posts: 4
  • iTrader: +0/-0
    • View Profile
Re: Web Application Setting in ASP.NET: Global.asax
« Reply #1 on: July 27, 2010, 09:15:49 AM »
The evolution of a parameter in the Global.asax file of the application requires recompilation together. Therefore, it will be impossible without access to source code Cons: To change the value of a parameter, it is necessary to recompile the entire application. Therefore, this method is not good for the parameters that must be changed frequently. Download a recompiled version will restart the entire application.

Offline cathelinedavid

  • Newbie
  • *
  • Posts: 5
  • iTrader: +0/-0
    • View Profile
Re: Web Application Setting in ASP.NET: Global.asax
« Reply #2 on: August 07, 2010, 03:33:26 PM »
To change the value of a parameter, it is necessary to recompile it. Therefore, this method is not good for the parameters to be changed frequently. Download recompiled version to restart everything. The development of a parameter in the Global.asax file of the application requires recompilation together. Therefore, it would be impossible without access to source code Cons:.

Offline maconfaris

  • Newbie
  • *
  • Posts: 5
  • iTrader: +0/-0
    • View Profile
Re: Web Application Setting in ASP.NET: Global.asax
« Reply #3 on: September 20, 2010, 07:03:07 PM »
Evolution of parameters in the Global.asax file its request for a summary way. Therefore, it would be impossible without access to source code Cons: If you want to change the parameter value, it is necessary to recompile it. Therefore, the method is good for the parameters must be changed frequently. Download recompiled version to restart everything.

Offline rogertilden

  • Newbie
  • *
  • Posts: 5
  • iTrader: +0/-0
    • View Profile
Re: Web Application Setting in ASP.NET: Global.asax
« Reply #4 on: September 28, 2010, 11:36:27 AM »
These all information which you can share over here is really very great. This solution is based on using the Application_Start method and global property Application. The Application property of HttpContext class returns HttpApplicationState object for the current HTTP request.
Divi WordPress Theme
Tags: