What is the Difference between Web.config and global.asax?
Can we write connection String code in global.asax?

Answer Posted / nidhi

Global.asax files allows you to executing ASP.Net application level events and setting application level variable.

The web.config file uses a predefined XML format. The entire content of the file is nested in a
root <configuration> element.

We can create more than one web.config file but we can't have more than one Global.asax file.

Yes we can write connection string in Global.asax file.

First store connection string in web.config file and fetch
in a Global.asax file using below code.

In global.asax

Application["VariableName"] = ConfigurationManager.ConnectionStrings["ConnStr"].
ConnectionString;

Now to fetch the value from applictaion variable

string conn = Application["VariableName"].ToString();

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Will the asp.net validators run in server side or client side? How do you do client-side validation in .net?

527


What are assemblies and namespaces and explain the difference between them ?

570


Explain the updatepanel?

586


What is the use of global.asax file?

553


What do you mean by marshalbyref?

646






What is the file extension of web service?

558


If I have more than one version of one assemblies, then how will I use old version (how/where to specify version number?) In my application?

522


How can i explain my project during interview?many time i expalain my project but they did't accept? please explain me.

5080


Where can I get information on cookies in asp.net?

570


What is the difference between file-based dependency and key-based dependency?

571


What is sql data source control in asp.net?

573


What is difference between session and cookie?

522


What is redirectpermanent in asp.net?

614


What are the types of caching in asp.net?

556


Describe in brief .net framework and its components.

547