Reputation: 417
I am new to .net and I usually had a common file which was having information of username,server,password,IPS and fixed integers in php and asp classic which i used to include in all files so that i could use them in any page. Since I have come to know that .net has no include function. how i can do it in asp.net?
Thank You
Upvotes: 2
Views: 363
Reputation: 6017
In addition to AppSettings mentioned by Digbyswift, & webconfig (which I would also recommend), you could use a module:
Module Module2
Public MyGlobalInteger As Integer = 0
End Module
Then it can be called from anywhere like:
Dim someOtherNumber As Integer = MyGlobalInteger + 5
Though, you may want to make it readonly, depending on your usage.
Upvotes: 0
Reputation: 9209
Strictly speaking if working with application configuration (such as DB connection strings) these are placed in web.config for web applications and app.config for others.
There's also settings files.
Check out ConfigurationManager
.
Other than that you must remember that "global variables are bad mmmkay" and aside from the various configuration files the nearest that you get to them would be public classes and properties.
Upvotes: 0
Reputation: 10410
You wouldn't necessarily use an include file for sharing variables across a site. In .Net you would normally store values like this in the AppSettings
section of the web.config file.
You can then access the values using code like:
string username = WebConfigurationManager.Appsettings["Username"];
Upvotes: 5