|
 |
aspx thread: Configuration files
Message #1 by mark_greenberg@l... on Mon, 19 Aug 2002 16:31:13
|
|
I have written a dll in .NET to be used by multiple applications, both
windows form and ASP.NET web apps. The dll connects to a database and
retrieves a value which is returned to the client application.
I need to store the database connect string in some type of configuration
file so it can be easily changed without updating the dll. Originally I
tried to use an application configuration file, for example,
MyApp.dll.config. I placed the file in the same folder with the dll but
the dll would not read the entries from the file,
ConfigurationSettings.AppSettings["ConnectString"] always returned null.
Next, I created an XML file with the connect string entries and added a
class to the dll to open and read the connect string from the file. I
used System.IO.Directory.GetCurrentDirectory() to determine the path to
the xml file. Then I created a windows forms app to test the dll, copied
all the files, (.exe, .dll, .xml) to the same folder and everything worked
fine.
For my ASP.NET app, I copied the dll and xml file to the \bin folder of
the web application, but when the dll attempts to open the xml config file
I receive this error: "Could not find file C:\WINNT\system32
\AppSettings.xml".
First of all, does anyone know why ConfigurationSettings.AppSettings
["ConnectString"] doesn't work (it does with a web app using web.config)
and next, why the web app can't find the file in the bin folder and
expects it to be in \winnt\system32?
Thanks for your help,
Mark
Message #2 by Pavankumar T <PavanKumar.T@k...> on Tue, 20 Aug 2002 09:37:53 +0530
|
|
Hi,
Yeah, even i faced this kind of problems. But, i changed my requirments.
Ie.. instead of writing into configuration file write the connect string
into Windows Registry.
Your DLL can easily read the registry with out any problem. If you need the
code let me know.
Hope this helps you.
Regards,
pavan.
-----Original Message-----
From: mark_greenberg@l... [mailto:mark_greenberg@l...]
Sent: Monday, August 19, 2002 10:01 PM
To: ASP+
Subject: [aspx] Configuration files
I have written a dll in .NET to be used by multiple applications, both
windows form and ASP.NET web apps. The dll connects to a database and
retrieves a value which is returned to the client application.
I need to store the database connect string in some type of configuration
file so it can be easily changed without updating the dll. Originally I
tried to use an application configuration file, for example,
MyApp.dll.config. I placed the file in the same folder with the dll but
the dll would not read the entries from the file,
ConfigurationSettings.AppSettings["ConnectString"] always returned null.
Next, I created an XML file with the connect string entries and added a
class to the dll to open and read the connect string from the file. I
used System.IO.Directory.GetCurrentDirectory() to determine the path to
the xml file. Then I created a windows forms app to test the dll, copied
all the files, (.exe, .dll, .xml) to the same folder and everything worked
fine.
For my ASP.NET app, I copied the dll and xml file to the \bin folder of
the web application, but when the dll attempts to open the xml config file
I receive this error: "Could not find file C:\WINNT\system32
\AppSettings.xml".
First of all, does anyone know why ConfigurationSettings.AppSettings
["ConnectString"] doesn't work (it does with a web app using web.config)
and next, why the web app can't find the file in the bin folder and
expects it to be in \winnt\system32?
Thanks for your help,
Mark
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #3 by "Christopher Reed" <CReed@m...> on Tue, 20 Aug 2002 07:54:56 -0500
|
|
Mark,
When you are using a DLL within an ASP.NET application, all application
specific settings go into the web.config file.
Hope this helps!
Chris
Christopher Reed
Application Analyst
Web Development Coordinator
Information Technology
City of Lubbock
creed@m...
"The oxen are slow, but the earth is patient."
>>> mark_greenberg@l... 4:31:13 PM 8/19/2002 >>>
I have written a dll in .NET to be used by multiple applications, both
windows form and ASP.NET web apps. The dll connects to a database and
retrieves a value which is returned to the client application.
I need to store the database connect string in some type of
configuration
file so it can be easily changed without updating the dll. Originally
I
tried to use an application configuration file, for example,
MyApp.dll.config. I placed the file in the same folder with the dll but
the dll would not read the entries from the file,
ConfigurationSettings.AppSettings["ConnectString"] always returned
null.
Next, I created an XML file with the connect string entries and added a
class to the dll to open and read the connect string from the file. I
used System.IO.Directory.GetCurrentDirectory() to determine the path to
the xml file. Then I created a windows forms app to test the dll,
copied
all the files, (.exe, .dll, .xml) to the same folder and everything
worked
fine.
For my ASP.NET app, I copied the dll and xml file to the \bin folder of
the web application, but when the dll attempts to open the xml config
file
I receive this error: "Could not find file C:\WINNT\system32
\AppSettings.xml".
First of all, does anyone know why ConfigurationSettings.AppSettings
["ConnectString"] doesn't work (it does with a web app using
web.config)
and next, why the web app can't find the file in the bin folder and
expects it to be in \winnt\system32?
Thanks for your help,
Mark
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #4 by "Christopher Reed" <CReed@m...> on Tue, 20 Aug 2002 07:59:28 -0500
|
|
Pavan,
<soapbox>
This is .NET - please step away from the registry!
One of the intents of .NET was to release applications from the
codependency problems of the Windows registry. If you are still using
the registry, then you will not benefit from the true application
independence using the .NET Framework.
</soapbox>
Chris
>>> PavanKumar.T@k... 11:07:53 PM 8/19/2002 >>>
Hi,
Yeah, even i faced this kind of problems. But, i changed my
requirments.
Ie.. instead of writing into configuration file write the connect
string
into Windows Registry.
Your DLL can easily read the registry with out any problem. If you need
the
code let me know.
Hope this helps you.
Regards,
pavan.
Message #5 by "Joe Dip****" <joedip****@h...> on Tue, 20 Aug 2002 14:18:05 +0000
|
|
HOW TO: Create a Custom ASP.NET Configuration Section Handler in Visual C#
.NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;q309045
HOW TO: Create a Custom ASP.NET Configuration Section Handler in Visual
Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;q318457
Pretty easy to do and it separates your configuration access from your UI.
So if you decide to move your configuration to something like SQL Server
(for scalability reasons or whatnot), you don't have to re-code everything
that accesses it. You would keep your configSection and just create a new
handler that accessed the DB instead of the config file.
Tobin
>>> mark_greenberg@l... 4:31:13 PM 8/19/2002 >>>
I have written a dll in .NET to be used by multiple applications, both
windows form and ASP.NET web apps. The dll connects to a database and
retrieves a value which is returned to the client application.
I need to store the database connect string in some type of
configuration
file so it can be easily changed without updating the dll. Originally
I
tried to use an application configuration file, for example,
MyApp.dll.config. I placed the file in the same folder with the dll but
the dll would not read the entries from the file,
ConfigurationSettings.AppSettings["ConnectString"] always returned
null.
Next, I created an XML file with the connect string entries and added a
class to the dll to open and read the connect string from the file. I
used System.IO.Directory.GetCurrentDirectory() to determine the path to
the xml file. Then I created a windows forms app to test the dll,
copied
all the files, (.exe, .dll, .xml) to the same folder and everything
worked
fine.
For my ASP.NET app, I copied the dll and xml file to the \bin folder of
the web application, but when the dll attempts to open the xml config
file
I receive this error: "Could not find file C:\WINNT\system32
\AppSettings.xml".
First of all, does anyone know why ConfigurationSettings.AppSettings
["ConnectString"] doesn't work (it does with a web app using
web.config)
and next, why the web app can't find the file in the bin folder and
expects it to be in \winnt\system32?
Thanks for your help,
Mark
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
Message #6 by "Mingkun Goh" <mangokun@h...> on Tue, 20 Aug 2002 16:26:11
|
|
Dim EventsPath As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
EventsPath = Server.MapPath("Events.xml")
If IO.File.Exists(EventsPath) Then
'Do whatever
End If
End Sub
Note: in this case, your XML file should be in the same directory as the
webpage which this code is executed.
In your case, if you put the XML file in the bin directory, then
Server.MapPath("Events.xml") should be changed to
Server.MapPath("bin/Events.xml")
Previous message:
> I have written a dll in .NET to be used by multiple applications, both
w> indows form and ASP.NET web apps. The dll connects to a database and
r> etrieves a value which is returned to the client application.
> I need to store the database connect string in some type of
configuration
f> ile so it can be easily changed without updating the dll. Originally I
t> ried to use an application configuration file, for example,
M> yApp.dll.config. I placed the file in the same folder with the dll but
t> he dll would not read the entries from the file,
C> onfigurationSettings.AppSettings["ConnectString"] always returned null.
> Next, I created an XML file with the connect string entries and added a
c> lass to the dll to open and read the connect string from the file. I
u> sed System.IO.Directory.GetCurrentDirectory() to determine the path to
t> he xml file. Then I created a windows forms app to test the dll, copied
a> ll the files, (.exe, .dll, .xml) to the same folder and everything
worked
f> ine.
> For my ASP.NET app, I copied the dll and xml file to the \bin folder of
t> he web application, but when the dll attempts to open the xml config
file
I> receive this error: "Could not find file C:\WINNT\system32
\> AppSettings.xml".
> First of all, does anyone know why ConfigurationSettings.AppSettings
[> "ConnectString"] doesn't work (it does with a web app using web.config)
a> nd next, why the web app can't find the file in the bin folder and
e> xpects it to be in \winnt\system32?
> Thanks for your help,
> Mark
>
|
|
 |