Web.Config File
The main benefits of having a config file in any web project is that it is a single file which contain Database connections Caching Settings Session states Error Handling Security and if you want to change any configuration setting than you just need to change at a single place and need not to deploy the project again and if you put all those code in different files like you are giving connection string in each file where you need and than you need a change in the string than you need to change the code in all the file at every place which will be a tedious task and Moreover you need to rebuild the solution and deploy it again.