What's the .NET way to....

Asphyxiated

New Member
Hi, i'm new to the .NET world.<BR>I was wandering, what's the .NET way of including files.<BR>exemple:<BR>I wish to make an include file containing my connection string so i won't have to write it in all my aspx files and i don't want to use global variables.<BR><BR>How do i do that ???<BR>I saw an exemple taking the connection string in a namespace, but where do i put this namespace and how do i make it ??<BR><BR>Thanks>I was wandering<BR><BR>well, stick around for a second and see if this helps you :)<BR><BR>in order to "globalize" your connection string, one approach would be to put it in your "web.config" file (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpconaccessingconfigurationsettings.asp)<BR><BR>then by including the "system.configuration" namespace in your code, you could gain access to it via "ConfigurationSettings.GetConfig()" or "ConfigurationSettings.AppSettings()" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpconaccessingconfigurationsettings.asp)<BR><BR>i realize that this doesn't answer your question about includes, but maybe it'll at least help you solve this particular problemIn the root of your Application you should have a file called web.config. <BR><BR>As I understand it this file is basically an XML view of the information that IIS stores when you create a virtual directory in ASP Classic.<BR><BR>Anyhow, you can add information that is specific to you application in that file in a Node called "appSettings".<BR><BR>Here is a <SNIP> from my test .NET application...<BR><BR> <?xml version="1.0" encoding="utf-8" ?><BR> <configuration><BR><BR> <BR> <appSettings><BR> <add key="dbString" value=http://aspmessageboard.com/archive/index.php/"Provider=InsertYourProvider;Data Source=InsertYourDBPath" /><BR> </appSettings> <BR> <BR> </configuration><BR> <BR>Then in my pages I Import the Systemb.Configuration Namespace like so...<BR><BR> <%@Import Namespace="System.Configuration"%><BR> <BR>And reference the dbString value like so...<BR><BR> Dim strPath As String = ConfigurationSettings.appSettings("dbString")<BR> <BR>Another cool article that I read today shows how emulate the Include files capability of ASP Classic, here's the link...<BR><BR> http://www.aspalliance.com/stevesmith/articles/includelets.asp<BR> <BR>HTH<BR><BR>Darren NeimkeYou could also consider using custom user controls. This probably won't be useful for including functions and sub procedures, but if you're employing standard footers, headers, or simliar stuff, it could be useful. Content within these files is saved as an .ascx file. Content can be dynamic ASP or static html. To call one of these controls, include this directive at the top of the page:<BR><BR><%@ Register tagprefix="whatever" tagname="test" src="myinclude.ascx" %><BR><BR>Then, at the location you'd like your include to appear, simply use the following:<BR><BR><whatever:test runat="server" />For headers and footers, I am solely using our (hm, ok, mine and scott guthries) free visual inheritance framework, which makes maintaining an changing big sites a breeze - even changes that you can not do with invludes, like moving menus from one place to the other. It is downloadable in a Beta 2 prerelease end of the week at our website http://www.thona-consulting.com/ free of charge, and I am right now working on making it fuly editable in VS7.<BR><BR>Queries can be sent to me at [email protected]<BR><BR>Thats much more powerfull than include files for headers and footers, as you can inherit over multiple levels.
 
Back
Top