在我的应用程序中处理设置的适当方式? [英] Appropriate way of dealing with settings in my app?

查看:57
本文介绍了在我的应用程序中处理设置的适当方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在经典ASP中,我曾经在我的网页的每个页面上都有一个名为settings.asp的文件,它包含了许多独特的设置

这个应用程序,其中包括数据库路径等。

我曾经设置了一些与服务器执行

脚本相关的值(参见下面的清单)。这样我就可以下载文件,编辑并在本地运行它们,然后再将它们放回生产服务器上

,而不必担心每次更改路径。


我现在的问题是:在.net中处理这个

的适当方法是什么?


/琳达


- settings.asp的部分内容 -


''---本地------ --------------

如果是InStr(Request.ServerVariables(" SERVER_NAME")),mydevserver,那么

DBPATH =" DRIVER = {Microsoft Access Driver(* .mdb)};

DBQ = D:\inetpub \wwwroot \customer\db\survey.mdb;"

BASE_URL =" http:// mydevserver / customer / survey /"

FILE_FOLDER =" / files /"

'' - - 在生产中--------------

ElseIf InStr(Request.ServerVariables(" SERVER_NAME")),

" customerserver .com")Th en $ / $
DBPATH =" DRIVER = {Microsoft Access Driver(* .mdb)};

DBQ = E:\webhotel \customers\customerserver.com \\ \\ db\su rvey.mdb;"

BASE_URL =" http://www.customerserver.com/survey"

FILE_FOLDER =" / virtualfiledir /

结束如果

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.ServerVariables("SERVER_NAME"), "mydevserver") Then
DBPATH = "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ=D:\inetpub\wwwroot\customer\db\survey.mdb;"
BASE_URL = "http://mydevserver/customer/survey/"
FILE_FOLDER = "/files/"
''--- In production--------------
ElseIf InStr(Request.ServerVariables("SERVER_NAME"),
"customerserver.com") Then
DBPATH = "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ=E:\webhotel\customers\customerserver.com\db\su rvey.mdb;"
BASE_URL = "http://www.customerserver.com/survey"
FILE_FOLDER = "/virtualfiledir/"
End If

推荐答案

嗨琳达,


使用web.config文件中的app settings部分:


< appSettings>

< add key =" FileFolder"值= QUOT; /富" />

< / appSettings>

您可以通过一些代码阅读设置:

string fileFolder =

ConfigurationSettings.AppSettings [" FileFolder"];


您可以将特定于环境的设置拉入外部文件

并引用该文件来自web.config:


< appSettings file =" devsettings.config" />


其中devsettings.config将包含<&的appSettings GT;元素。

http://odetocode.com/Articles/ 345.aspx


HTH,


-

Scott
http://www.OdeToCode.com/blogs/scott/

星期五,2005年3月18日16:25:25 +0100,Linda

< linda(at)ordinarystar.com>写道:
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 =
ConfigurationSettings.AppSettings["FileFolder"];

And you can pull environment specific settings into an external file
and reference the file from web.config:

<appSettings file="devsettings.config"/>

Where devsettings.config 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)ordinarystar.com> wrote:
在经典ASP中我曾经有一个名为settings.asp的文件包含在我的网页的每个页面上,它包含了许多不同的设置<这个应用程序,其中包括数据库路径等。
我曾经设置了一些与服务器执行
脚本相关的值(参见下面的清单)。这样我就可以下载文件,编辑并在本地测试运行它们,然后再将它们放回生产服务器上,而不必担心每次都改变路径。
我现在的问题是:在.net中处理这个
的适当方法是什么?

/ Linda

- settings.asp的部分内容 -

''---本地--------------------
如果是InStr(Request.ServerVariables(" SERVER_NAME) ;),mydevserver)然后
DBPATH =" DRIVER = {Microsoft Access Driver(* .mdb)};
DBQ = D:\inetpub \wwwroot \customer\db \ survey.mdb;"
BASE_URL =" http:// mydevserver / customer / survey /"
FILE_FOLDER =" / files /"
''---在生产中--------------
ElseIf InStr(Request.ServerVariables(" SERVER_NAME"),
" customerserver.com")然后
DBPATH =" DRIVER = {Microsoft Access Driver(* .md b)} ;;
DBQ = E:\\\\\\\\\ .com / survey"
FILE_FOLDER =" / virtualfiledir /"
End If
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.ServerVariables("SERVER_NAME"), "mydevserver") Then
DBPATH = "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ=D:\inetpub\wwwroot\customer\db\survey.mdb;"
BASE_URL = "http://mydevserver/customer/survey/"
FILE_FOLDER = "/files/"
''--- In production--------------
ElseIf InStr(Request.ServerVariables("SERVER_NAME"),
"customerserver.com") Then
DBPATH = "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ=E:\webhotel\customers\customerserver.com\db\s urvey.mdb;"
BASE_URL = "http://www.customerserver.com/survey"
FILE_FOLDER = "/virtualfiledir/"
End If






在网络中。配置你可以使用< appSettings>部分存储您的自定义

应用程序设置(请注意它区分大小写):


< configuration>

< appSettings>

< add key =" SomeKey"值= QUOT; someValue中" />

< / appSettings>

< / configuration>


然后在你的app中:


string val = System.Configuration.ConfigurationSettings.AppSett ings [" SomeKey"];

//在这里使用val ....


-Brock

DevelopMentor
http: //staff.develop.com/ballen
In web.config you can use the <appSettings> section to store your custom
application settings (note that it''s case sensitive):

<configuration>
<appSettings>
<add key="SomeKey" value="SomeValue" />
</appSettings>
</configuration>

Then in you app:

string val = System.Configuration.ConfigurationSettings.AppSett ings["SomeKey"];
// use val here....

-Brock
DevelopMentor
http://staff.develop.com/ballen
在经典的ASP中我曾经有一个名为settings.asp的文件包含在每个
页面上我的网站,它包含了许多不同的设置,这个应用程序是独一无二的,其中包括数据库路径等。
我曾经设置了一些与服务器执行相关的值?
脚本(见下面的清单)。这样我就可以下载文件,编辑
并在本地测试运行它们,然后再将它们放回到生产服务器上

,而不必担心每次更改路径。
现在我的问题是:在.net中处理这个问题的适当方法是什么?

/琳达
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






设置一个类文件中的所有常量/属性,你编译成一个程序集并放在/ bin

目录中你的申请表格。


从那里调用任何常数/属性很容易.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" <琳达(AT)ordinarystar.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP10.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)ordinarystar.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
经典ASP我以前在我的网页的每个页面都有一个名为settings.asp的文件,它由许多不同的设置组成,其中包括数据库路径等。
我过去常常设置一些服务器执行
脚本的值(参见下面的清单)。这样我就可以下载文件,编辑并在本地测试运行它们,然后再将它们放回生产服务器上,而不必担心每次都改变路径。
我现在的问题是:在.net中处理这个
的适当方法是什么?

/ Linda
- settings.asp的部分内容 -

''---本地--------------------
如果是InStr(Request.ServerVariables(" SERVER_NAME")), ; mydevserver")然后
DBPATH =" DRIVER = {Microsoft Access Driver(* .mdb)};
DBQ = D:\inetpub \wwwroot \customer\db\survey。 mdb;"
BASE_URL =" http:// mydevserver / customer / survey /"
FILE_FOLDER =" / files /"
''---在制作中 - ------------
ElseIf InStr(Request.ServerVariables(SERVER_NAME),
customerserver.com)然后
DBPATH =" DRIVER = {Microsoft Access驱动程序(* .mdb)};
DBQ = E:\webhotel \customers\customerserver.com \db\su rvey.mdb;"
BASE_URL =" http:// www。 customerserver.com/survey"
FILE_FOLDER =" / virtualfiledir /"
结束如果
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.ServerVariables("SERVER_NAME"), "mydevserver") Then
DBPATH = "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ=D:\inetpub\wwwroot\customer\db\survey.mdb;"
BASE_URL = "http://mydevserver/customer/survey/"
FILE_FOLDER = "/files/"
''--- In production--------------
ElseIf InStr(Request.ServerVariables("SERVER_NAME"),
"customerserver.com") Then
DBPATH = "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ=E:\webhotel\customers\customerserver.com\db\su rvey.mdb;"
BASE_URL = "http://www.customerserver.com/survey"
FILE_FOLDER = "/virtualfiledir/"
End If



这篇关于在我的应用程序中处理设置的适当方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆