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

Results 1 to 5 of 5

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

  1. #1
    David Bergeron Guest

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

    Hi, i&#039;m new to the .NET world.<BR>I was wandering, what&#039;s the .NET way of including files.<BR>exemple:<BR>I wish to make an include file containing my connection string so i won&#039;t have to write it in all my aspx files and i don&#039;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

  2. #2
    Join Date
    Dec 1969

    Default RE: What's the .NET way to....

    &#062;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>th en 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&#039;t answer your question about includes, but maybe it&#039;ll at least help you solve this particular problem

  3. #3
    Darren Neimke Guest

    Default This is how I do it.

    In 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 &lt;SNIP&#062; from my test .NET application...<BR><BR> &lt;?xml version="1.0" encoding="utf-8" ?&#062;<BR> &lt;configuration&#062;<BR><BR> <BR> &lt;appSettings&#062;<BR> &lt;add key="dbString" value="Provider=InsertYourProvider;Data Source=InsertYourDBPath" /&#062;<BR> &lt;/appSettings&#062; <BR> <BR> &lt;/configuration&#062;<BR> <BR>Then in my pages I Import the Systemb.Configuration Namespace like so...<BR><BR> &lt;%@Import Namespace="System.Configuration"%&#062;<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&#039;s the link...<BR><BR> http://www.aspalliance.com/stevesmith/articles/includelets.asp<BR> <BR>HTH<BR><BR>Darren Neimke

  4. #4
    Join Date
    Dec 1969

    Default RE: What's the .NET way to....

    You could also consider using custom user controls. This probably won&#039;t be useful for including functions and sub procedures, but if you&#039;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>&#060;%@ Register tagprefix="whatever" tagname="test" src="myinclude.ascx" %&#062;<BR><BR>Then, at the location you&#039;d like your include to appear, simply use the following:<BR><BR>&#060;whatever:test runat="server" /&#062;

  5. #5
    Thomas Tomiczek Guest

    Default RE: What's the .NET way to....

    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 t.tomiczek@thona-consulting.com<BR><BR>Thats much more powerfull than include files for headers and footers, as you can inherit over multiple levels.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts