In classic ASP I used to have a file called settings.asp included on every
page of my web, it consisted of a number of different settings unique to
this application, among them the database path etc.
I used to set some of the values contidional to which server executed the
script (see listing below). This way I could download the files, edit and
test run them locally, then put them back on the production server again
without having to worry about changing the paths each time.
My question now is: What would be the appropriate way of dealing with this
in .net?
/ Linda
-- partial content of settings.asp --
'--- Locally--------------------
If InStr(Request.S erverVariables( "SERVER_NAM E"), "mydevserve r") Then
DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)};
DBQ=D:\inetpub\ wwwroot\custome r\db\survey.mdb ;"
BASE_URL = "http://mydevserver/customer/survey/"
FILE_FOLDER = "/files/"
'--- In production--------------
ElseIf InStr(Request.S erverVariables( "SERVER_NAM E"),
"customerserver .com") Then
DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)};
DBQ=E:\webhotel \customers\cust omerserver.com\ db\survey.mdb;"
BASE_URL = "http://www.customerser ver.com/survey"
FILE_FOLDER = "/virtualfiledir/"
End If 19 1765
Hi Linda,
Use the app settings section in your web.config file:
<appSettings>
<add key="FileFolder " value="/foo" />
</appSettings>
You can read the settings with a little bit of code:
string fileFolder =
ConfigurationSe ttings.AppSetti ngs["FileFolder "];
And you can pull environment specific settings into an external file
and reference the file from web.config:
<appSettings file="devsettin gs.config"/>
Where devsettings.con fig would contain an <appSettings> element. http://odetocode.com/Articles/345.aspx
HTH,
--
Scott http://www.OdeToCode.com/blogs/scott/
On Fri, 18 Mar 2005 16:25:25 +0100, "Linda"
<linda(at)ordin arystar.com> wrote: In classic ASP I used to have a file called settings.asp included on every page of my web, it consisted of a number of different settings unique to this application, among them the database path etc. I used to set some of the values contidional to which server executed the script (see listing below). This way I could download the files, edit and test run them locally, then put them back on the production server again without having to worry about changing the paths each time.
My question now is: What would be the appropriate way of dealing with this in .net?
/ Linda -- partial content of settings.asp --
'--- Locally-------------------- If InStr(Request.S erverVariables( "SERVER_NAM E"), "mydevserve r") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=D:\inetpub \wwwroot\custom er\db\survey.md b;" BASE_URL = "http://mydevserver/customer/survey/" FILE_FOLDER = "/files/" '--- In production-------------- ElseIf InStr(Request.S erverVariables( "SERVER_NAM E"), "customerserve r.com") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=E:\webhote l\customers\cus tomerserver.com \db\survey.mdb; " BASE_URL = "http://www.customerser ver.com/survey" FILE_FOLDER = "/virtualfiledir/" End If
In web.config you can use the <appSettings> section to store your custom
application settings (note that it's case sensitive):
<configuratio n>
<appSettings>
<add key="SomeKey" value="SomeValu e" />
</appSettings>
</configuration>
Then in you app:
string val = System.Configur ation.Configura tionSettings.Ap pSettings["SomeKey"];
// use val here....
-Brock
DevelopMentor http://staff.develop.com/ballen In classic ASP I used to have a file called settings.asp included on every page of my web, it consisted of a number of different settings unique to this application, among them the database path etc. I used to set some of the values contidional to which server executed the script (see listing below). This way I could download the files, edit and test run them locally, then put them back on the production server again without having to worry about changing the paths each time. My question now is: What would be the appropriate way of dealing with this in .net?
/ Linda
Set all the constants/properties in a class file which
you compile to an assembly and place in the /bin
directory of your application.
It's easy to call any constant/property from that .dll
Juan T. Llibre
ASP.NET MVP http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======
"Linda" <linda(at)ordin arystar.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. In classic ASP I used to have a file called settings.asp included on every page of my web, it consisted of a number of different settings unique to this application, among them the database path etc.
I used to set some of the values contidional to which server executed the script (see listing below). This way I could download the files, edit and test run them locally, then put them back on the production server again without having to worry about changing the paths each time.
My question now is: What would be the appropriate way of dealing with this in .net?
/ Linda
-- partial content of settings.asp --
'--- Locally-------------------- If InStr(Request.S erverVariables( "SERVER_NAM E"), "mydevserve r") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=D:\inetpub\ wwwroot\custome r\db\survey.mdb ;" BASE_URL = "http://mydevserver/customer/survey/" FILE_FOLDER = "/files/" '--- In production-------------- ElseIf InStr(Request.S erverVariables( "SERVER_NAM E"), "customerserver .com") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=E:\webhotel \customers\cust omerserver.com\ db\survey.mdb;" BASE_URL = "http://www.customerser ver.com/survey" FILE_FOLDER = "/virtualfiledir/" End If
You guys are quick, thanks!!
I have looked briefly into the world of app settings before, and it solves
most of my problem, at least as long as I am the only developer involved.
But at some point there will be other developers, designers etc involved,
who have the bad habit of always downloading/uploading the entire app, of
course resulting in the exact same files in both (or all) locations.
Is there a way to solve that, other than educating my co-workers ;)
Is there a way to force the use of different app setting-files for different
locations. Or maybe it is posible to refer to an app setting file in a
directory outside of the actual application folder, where those co-workers
would never think to look?
/ Linda
"Scott Allen" <sc***@nospam.o detocode.com> wrote in message
news:4q******** *************** *********@4ax.c om... Hi Linda,
Use the app settings section in your web.config file:
<appSettings> <add key="FileFolder " value="/foo" /> </appSettings>
You can read the settings with a little bit of code: string fileFolder = ConfigurationSe ttings.AppSetti ngs["FileFolder "];
And you can pull environment specific settings into an external file and reference the file from web.config:
<appSettings file="devsettin gs.config"/>
Where devsettings.con fig would contain an <appSettings> element.
http://odetocode.com/Articles/345.aspx
HTH,
-- Scott http://www.OdeToCode.com/blogs/scott/
On Fri, 18 Mar 2005 16:25:25 +0100, "Linda" <linda(at)ordin arystar.com> wrote:
In classic ASP I used to have a file called settings.asp included on
everypage of my web, it consisted of a number of different settings unique to this application, among them the database path etc. I used to set some of the values contidional to which server executed the script (see listing below). This way I could download the files, edit and test run them locally, then put them back on the production server again without having to worry about changing the paths each time.
My question now is: What would be the appropriate way of dealing with
thisin .net?
/ Linda -- partial content of settings.asp --
'--- Locally-------------------- If InStr(Request.S erverVariables( "SERVER_NAM E"), "mydevserve r") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=D:\inetpub \wwwroot\custom er\db\survey.md b;" BASE_URL = "http://mydevserver/customer/survey/" FILE_FOLDER = "/files/" '--- In production-------------- ElseIf InStr(Request.S erverVariables( "SERVER_NAM E"), "customerserve r.com") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=E:\webhote l\customers\cus tomerserver.com \db\survey.mdb; " BASE_URL = "http://www.customerser ver.com/survey" FILE_FOLDER = "/virtualfiledir/" End If
I have a sample of building your own custom configuration sections which
uses the XmlSerializer. This is a very common technique in v1.x: http://staff.develop.com/ballen/samp...nfigSample.zip
-Brock
DevelopMentor http://staff.develop.com/ballen You guys are quick, thanks!!
I have looked briefly into the world of app settings before, and it solves most of my problem, at least as long as I am the only developer involved. But at some point there will be other developers, designers etc involved, who have the bad habit of always downloading/uploading the entire app, of course resulting in the exact same files in both (or all) locations. Is there a way to solve that, other than educating my co-workers ;) Is there a way to force the use of different app setting-files for different locations. Or maybe it is posible to refer to an app setting file in a directory outside of the actual application folder, where those co-workers would never think to look? / Linda
"Scott Allen" <sc***@nospam.o detocode.com> wrote in message news:4q******** *************** *********@4ax.c om...
Hi Linda,
Use the app settings section in your web.config file:
<appSettings> <add key="FileFolder " value="/foo" /> </appSettings> You can read the settings with a little bit of code: string fileFolder = ConfigurationSe ttings.AppSetti ngs["FileFolder "];
And you can pull environment specific settings into an external file and reference the file from web.config:
<appSettings file="devsettin gs.config"/>
Where devsettings.con fig would contain an <appSettings> element.
http://odetocode.com/Articles/345.aspx
HTH,
-- Scott http://www.OdeToCode.com/blogs/scott/ On Fri, 18 Mar 2005 16:25:25 +0100, "Linda" <linda(at)ordin arystar.com> wrote: In classic ASP I used to have a file called settings.asp included on every page of my web, it consisted of a number of different settings unique to this application, among them the database path etc. I used to set some of the values contidional to which server executed the script (see listing below). This way I could download the files, edit and test run them locally, then put them back on the production server again without having to worry about changing the paths each time. My question now is: What would be the appropriate way of dealing with this in .net?
/ Linda
-- partial content of settings.asp --
'--- Locally-------------------- If InStr(Request.S erverVariables( "SERVER_NAM E"), "mydevserve r") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=D:\inetpub\ wwwroot\custome r\db\survey.mdb ;" BASE_URL = "http://mydevserver/customer/survey/" FILE_FOLDER = "/files/" '--- In production-------------- ElseIf InStr(Request.S erverVariables( "SERVER_NAM E"), "customerserver .com") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=E:\webhotel \customers\cust omerserver.com\ db\survey.mdb;" BASE_URL = "http://www.customerser ver.com/survey" FILE_FOLDER = "/virtualfiledir/" End If
I agree with both schools of thought (web.config and class). There are uses
for both. For example, you can only store text data in the web.config. You
can store objects in a class. On the other hand, the web.config is read into
memory and remains memory-resident for the life of the app. A class can have
static methods that don't require instantiation, but often will require
instantiation. So, keep in mind what your options are, and use the
appropriate method.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:OV******** ******@TK2MSFTN GP15.phx.gbl... Set all the constants/properties in a class file which you compile to an assembly and place in the /bin directory of your application.
It's easy to call any constant/property from that .dll Juan T. Llibre ASP.NET MVP http://asp.net.do/foros/ Foros de ASP.NET en Español Ven, y hablemos de ASP.NET... =============== =======
"Linda" <linda(at)ordin arystar.com> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. In classic ASP I used to have a file called settings.asp included on every page of my web, it consisted of a number of different settings unique to this application, among them the database path etc.
I used to set some of the values contidional to which server executed the script (see listing below). This way I could download the files, edit and test run them locally, then put them back on the production server again without having to worry about changing the paths each time.
My question now is: What would be the appropriate way of dealing with this in .net?
/ Linda
-- partial content of settings.asp --
'--- Locally-------------------- If InStr(Request.S erverVariables( "SERVER_NAM E"), "mydevserve r") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=D:\inetpub\ wwwroot\custome r\db\survey.mdb ;" BASE_URL = "http://mydevserver/customer/survey/" FILE_FOLDER = "/files/" '--- In production-------------- ElseIf InStr(Request.S erverVariables( "SERVER_NAM E"), "customerserver .com") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=E:\webhotel \customers\cust omerserver.com\ db\survey.mdb;" BASE_URL = "http://www.customerser ver.com/survey" FILE_FOLDER = "/virtualfiledir/" End If
One way might be to encapsulate it into a Web User control. They are easy
to make though they don't have much visual representation at design time.
In your case that's no big deal.
Also, keep in mind that straight ASP techniques generally still work in
ASP.NET. They just might be the "old way" of doing things.
You could perhaps put a script block into each web form. They look
something like:
<script language=C# runat=server>
(code here)
</script>
You might try using the "src" attribute to refer to your asp include file.
I've never tried combining "runat=serv er" with a "src" attribute, but I
imagine it should work.
-jv
"Linda" <linda(at)ordin arystar.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. In classic ASP I used to have a file called settings.asp included on every page of my web, it consisted of a number of different settings unique to this application, among them the database path etc. I used to set some of the values contidional to which server executed the script (see listing below). This way I could download the files, edit and test run them locally, then put them back on the production server again without having to worry about changing the paths each time.
My question now is: What would be the appropriate way of dealing with this in .net?
/ Linda
Actually, now that I reread your post, I would recommend putting the
settings in your WEB.CONFIG file and using the folllowing collection object
to retrieve them in each page:
System.Configur ation.Configura tionSettings.Ap pSettings
Search for "Introducti on to Dynamic Properties" in the online help for
details.
"Linda" <linda(at)ordin arystar.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. In classic ASP I used to have a file called settings.asp included on every page of my web, it consisted of a number of different settings unique to this application, among them the database path etc. I used to set some of the values contidional to which server executed the script (see listing below). This way I could download the files, edit and test run them locally, then put them back on the production server again without having to worry about changing the paths each time.
My question now is: What would be the appropriate way of dealing with this in .net?
/ Linda -- partial content of settings.asp --
'--- Locally-------------------- If InStr(Request.S erverVariables( "SERVER_NAM E"), "mydevserve r") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=D:\inetpub\ wwwroot\custome r\db\survey.mdb ;" BASE_URL = "http://mydevserver/customer/survey/" FILE_FOLDER = "/files/" '--- In production-------------- ElseIf InStr(Request.S erverVariables( "SERVER_NAM E"), "customerserver .com") Then DBPATH = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=E:\webhotel \customers\cust omerserver.com\ db\survey.mdb;" BASE_URL = "http://www.customerser ver.com/survey" FILE_FOLDER = "/virtualfiledir/" End If
A couple of options occur off the top of my head:
a) configure your team's FTP software to ignore "web.config " files
(Dreamweaver does it with "cloaking", NAnt and other tools with
regular expressions of some sort)
b) if your deployments are to known servers with predictable and
stable URLs, you could hard code the settings into an assembly (dll)
with a static accessor that does some sort of switching on the current
URL.
b.1) depending on how complicated your configuration is, you may even
draft an Interface and then derive an actual configuration class for
each deployment.
then again, these 'b' options may result in deploying lots of extra
code with each setup, so a simpler solution, depending on your
toolset, would be 'a'. :-)
David. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tom Willis |
last post by:
How are the expert pythoneers dealing with config files?
Is there anything similair to .net's config files or java's .properties?
A quick search on google didn't return anything that looked useful,
and I almost would expect to see some module that would be for dealing
with config information.
I can think of at least one way to do it,...
|
by: Michael J. Hudson |
last post by:
I'm not sure what good attaching a stylesheet to a Microsoft Word
document does. When you save the document as an HTML file, Word
throws in all of its style and font settings into the HTML file AND
these settings override the same properties you may have specified in
your stylesheet. So, what good is it to attach a stylesheet????
I've...
|
by: Igor Kramarsich - EDIT |
last post by:
I'm having problems dealing with dates in my queries/SQL code.
I need a search digit date. In form define date field without format I
receive results.
But I go to define date filed with short date format I receive error. In my
regional settings are in the format "dd.mm.yyyy".
What I need to do?
|
by: Lenn |
last post by:
Hello,
Just some background: I'm developing an application that basically executes
series of tasks. So far I have 2 group of tasks run on different threads (2
different threads). Which run in parallel. Now, these threads need read-only
access to app config settings Object. So, I have one public class with 1
static field - Hashtable which...
|
by: SenthilVel |
last post by:
Hi
I am in the Process of conversion of my existing 1.1 Dotnet Code to 2.0
framework.
for each project when i compile in VS2005 , i get this error\warning:
Use command line option '/keyfile' or appropriate project settings instead
of 'AssemblyKeyFile'
| |
by: SenthilVel |
last post by:
Hi
I am in the Process of conversion of my existing 1.1 Dotnet Code to 2.0
framework.
for each project when i compile in VS2005 , i get this error\warning:
Use command line option '/keyfile' or appropriate project settings instead
of 'AssemblyKeyFile'
|
by: Nathan Sokalski |
last post by:
I am trying to test out an ASP.NET web service I wrote, but the Add Web
Reference dialog gives me the following errors:
The proxy settings on this computer are not configured correctly for web
discovery. Press F1 for more information.
Parser Error Message: Could not create type 'WebApplication1.WebService1'.
|
by: RP |
last post by:
I am using SQL Server 2005 as backend. I have a Text Box that accepts
Date in the format dd-MM-yyyy. But when I attempt to insert a record,
an error is displayed: Cannot convert char to DateTime ....
Actually, when the text box has entry like 22-10-2005, it considers 22
as month whereas it is DD. How to convert the Text Box value to an...
|
by: AmberJain |
last post by:
Windows Autorun FAQs: Programs dealing with autoruns
Linked from the Original article- "Windows Autorun FAQs: Description".
Que: Can you list programs that help me to view/modify the autoruns on my Windows PC?
Ans: Other than Sysinternals Autoruns, there are only a few programs which are good enough to be used when dealing with autoruns....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |