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

Let's say I have an existing application written using vb6 and this application utilizes windows 2000 com+ transaction services. How would you approach migrating this application to.net?

714


How does session state work in asp.net?

709


How is application management and maintenance improved in asp.net 2.0?

729


What is & in a url?

716


What is server infrastructure?

797


What is cas?

803


What is the best Macanism to clear the Cache in asp.net

940


List down the sequence of methods called during the page load.

709


What are merge modules?

749


What’s the difference between response .redirect and server.transfer?

718


Explain the difference between webfarm and webgardens in .net?

718


Which is an advantage of application service providers?

669


Why is mvc better than asp.net?

744


Describe the differences between the lifecycles of Windows services and Standard EXE?

823


What is the use of placeholder control? Can we see it at runtime?

803