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

Difference between DataGid and Girdview? Difference b/w .Net 2.0, 3.0 and 3.5 ? Diff b/w dispose & Finialize Methods?

2029


How to rename a table using sql queries?

572


What is the purpose of using MVC programming pattern in ASP.NET?

557


What is an axd file?

594


Explain how can we inherit a static member?

532






Is it possible to migrate visual interdev design-time controls to asp.net?

563


To display data in the combo box, prior to setting the Data Source, what kind of property on a Combo Box do you set with a column name?

605


Why is xap important?

601


What is the concepts of globalization and localization in .net?

530


What threading model used in asp and asp.net?

576


How you can access the values from the Repeater control in ASP.NET?

579


Can you explain the importance of finalize method in .net?

591


What is form submit?

520


How to find last error which occurred in Asp.net ?

685


Less than one page, how many windows will you be able to maintain?

565