📄 4.htm
字号:
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>4</title>
</head>
<body>
<p align="center"><b><font size="5" color="#0078FF">
<span style="background-color: #CCCCCC">4. ASP最佳实作技巧</span></font></b></p>
<div language="javascript" id="tab1" style="line-height: 25px; margin-left: 20px" ondragover="return tab1_ondragover()">
<font face="arial" color="#000000" size="2" style="line-height: 25px">
本章将为大家介绍一些有助於开发Active Server Pages(ASP)应用程式的技巧,这些技巧可以让ASP具有良好的组织性,安全可靠的目录和档案结构,并能有效率地执行。在这些指导下所建立的ASP网页之风格将具有一致性、可读性,也将更容易维护。</font><p>
<font face="arial" color="#000000" size="2" style="line-height: 25px">
为了获得最好的成果,您必须先熟悉IIS5.0线上说明文件的内容,特别是〈Active Server
Pages手册〉中的〈建构ASP网页〉和〈Developing Web Applications〉。</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
本章节介绍了计划和开发ASP专案的相关次序。有关开发软体元件的更详细资讯,请参阅本书的 <a target="_new" href="http://e-msbooks.com/relaunch/XML/paser.asp?src=957-2085-16-6_202.xml#202" style="line-height: 25px">第2章〈开发Web应用程式〉</a> 或者是IIS
5.0的线上说明文件。</font></p>
<p><font face="arial" color="#3e74d7" size="3" style="line-height: 25px">
<b style="line-height: 25px">本章内容<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
何时使用ASP</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
专案目录和档案</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
ASP网页内的指令档风格指导</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
HTML标准</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">指令档效能</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">其他资源</font></p>
<a name="204001" style="line-height: 25px">
<p><font face="arial" color="#3e70d7" size="5" style="line-height: 25px">
<b style="line-height: 25px">何时使用ASP<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
ASP是一种伺服器端的指令档环境,它能在使用者需要时轻松的呈现出动态的Web网页。使用ASP,您可以根据使用者的特点来替他们订定个人化的服务。</font></p>
<font face="arial" color="#000000" size="2" style="line-height: 25px">
<ul style="line-height: 25px">
<li style="line-height: 25px">根据使用者浏览器的构造和版本来决定相对应格式的网页。<br style="line-height: 25px">
</li>
<li style="line-height: 25px">
透过COM元件,收集HTML表单所送出的资料,使浏览者连线到伺服器端的资讯来源,以更新资料库或检索资讯。<br style="line-height: 25px">
</li>
<li style="line-height: 25px">开发网页应用程式,使浏览者可以连线资料来源,像是Microsoft SQL Server
或者是IBM DB2上的资料库。<br style="line-height: 25px">
</li>
</ul>
</font>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
因为ASP能在多使用者和多执行绪方面表现良好,您可以预期到ASP会比CGI具备更好的效能。</font></p>
<p><font face="arial" color="#3e78d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">为使用者自订资讯<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
不论使用者是在网路的什麽地方,ASP都可以收集到他们的资料,这些资料最後也能透过ASP传回给使用者。举例来说,使用者可以透过HTML表单,向一个房地产网站送出所需要的房屋资料(卧室数目、价格范围、位置等等),然後ASP会向资料库取出符合这些条件的资讯。</font></p>
<p><font face="arial" color="#3e78d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">线上更新记录<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
ASP可以利用使用者在表单中所送出的资料来维护资料库。例如,如果员工们有存取个人线上资料库的权限,他们就可以在自己的目录下更新资料。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">何时不使用ASP<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
如果指令档所做的工作在浏览器端就可以简单解决,这样的指令档就不应在ASP网页中呼叫,因为ASP会耗费伺服器资源。为了使浏览器完成资料确认、计算或做简单的条件输出,您可以节约系统资源而不需要使用ASP,例如,您可以使用用户端的指令档来确认输入资料的正确性,或者依使用者输入的贷款来计算利息。</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
为了更有效的利用伺服器资源,如果网页必须包含指令档,则请以 .asp做为副档名。如果网页只有 HTML语法,则以 .htm做为副档名。</font></p>
</a><a name="204002" style="line-height: 25px">
<p><font face="arial" color="#3e70d7" size="5" style="line-height: 25px">
<b style="line-height: 25px">专案目录和档案<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#3e72d7" size="4" style="line-height: 25px">
<b style="line-height: 25px">组织应用程式目录和档案<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
这部分提供了一个展示ASP应用程式的储存结构和存取权限的范例,您可以用这个范例来建立一个一致、安全和易於管理的ASP应用程式。</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
以下列出的目录和档案的结构与属性比名称更加重要。</font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px">/ Application_Name
Default.htm
Global.asa
/ Classes
/ Content
/ ASP
*.asp
/ HTM
*.htm
/ Images
/ Media
/ Themes
/ Data(不包含在网站目录)
/ DLL(不包含在网站目录)
/* dll
/ Helper_Files(不包含在网站目录)</pre>
</font>
</div>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">应用程式根目录<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
应用程式的根目录名称应该能清晰的表示出该站台的主旨。例如,可以将一个关於财务研究的应用程式命名为 / Financial_
Research。请避免使用一些容易和站台标准子目录名称混淆的名称来命名应用程式的根目录,例如 /Media 或者
/Content。另外,也请避开那些读起来像数字或程式码的名称,如 /FR98346A。</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
为了避免对正在提供服务的站台造成负面的影响,请在开发测试环境中开发应用程式。一个简单的方法就是在IIS的HTTP根目录 /InetPub/wwwroot下开发新的应用程式。待一切准备就绪後,再将它们移植到执行环境内,也就是/InetPub/wwwroot下的相对应目录中。</font></p>
<hr style="line-height: 25px">
<p>
<font face="Arial" color="#3e77d7" size="3" Black style="line-height: 25px">
<b style="line-height: 25px">说明</b></font> </p>
<p><font face="arial" color="black" size="2" style="line-height: 25px">/InetPub/wwwroot
是Microsoft Visual InterDev和Microsoft FrontPage Web文件的根目录。如果Web应用程式没有放置在 /InetPub/wwwroot下,那麽将无法存取这些应用程式。</font></p>
<hr style="line-height: 25px">
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
每个应用程式的根目录都应该至少包括以下这些档案</font></p>
<font face="arial" color="#000000" size="2" style="line-height: 25px">
<ul style="line-height: 25px">
<li style="line-height: 25px">Default.htm 或者Default. asp<br style="line-height: 25px">
</li>
<li style="line-height: 25px">Global.asa<br style="line-height: 25px">
</li>
</ul>
</font>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">Default.htm、Default. asp<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
Default.htm 或 Default.
asp是应用程式预设的主网页,这可以让使用者只要透过输入伺服器名称和应用程式根目录名称就能找到您的站台。例如,使用者能输入 </font></a><font face="arial" color="#000000" size="2" style="line-height: 25px"><a target="_new" href="http://msdn.microsoft.com/default.asp" style="line-height: 25px">http://msdn.microsoft.com/default.asp</a> 来存取MSDN
Online,而不需要输入网页的名称。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">Global.asa<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
Global.asa档案指定了事件指令档,并宣告是属於Application 或
Session物件的范围。例如,Global.asa指令档在启动时让Application 或
Session变数可以使用。Global.asa必须放在应用程式的根目录中。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/Classes<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">在
/Classes目录中存放了应用程式所需要用到的Java类别。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/Content<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">在
/Content目录下存放了所有的网页(除了Default.htm外)和使用者可能需要从站台上获得的媒体档案。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/ASP<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
/Content目录下的
/ASP子目录包含着有伺服器端指令档的网页。因为ASP需要执行指令档,所以这个目录必须具备执行的权限。从简化权限管理和站台安全的角度出发,您应该将所有的指令档网页存放在这里。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/HTM<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
/Content目录下的 /HTM子目录中存放了所有的标准HTML网页。这个目录是唯读的并且没有执行权限。存放在这里的伺服器端指令档网页将不能够执行。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/Images<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
/Content目录下的 /Images子目录存放了与站台主题较不相关的图片,例如一些标准的按钮和小图示。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/Media<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
将应用程式会用到的影像视讯档案(.avi)以及类似的物件存放在 /Content目录下的 /Media子目录中。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/Themes<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
为使应用程式能方便的改变站台的外观,您可以使用 /Themes子目录,它也位在
/Content目录下。这个子目录包括样式表、按钮、图示、规则和类似的物件。如此一来,您可以透过修改一些和网站主题相关的物件来改变应用程式的外观。每个
/Themes子目录下的项目可以被动态的连结到这些应用程式变数的虚拟路径上。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/Data<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
/Data目录包括了存取资料库的相关资讯,例如:应用程式所需要的SQL指令档、以档案为基础的资料集名称,以及其他类似的资料。不要将这个目录放置在站台目录下,这样未被授权的使用者将可以存取企业或是个人的资讯。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">/DLLs<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
/DLLS子目录中放置有 Microsoft Component Object Model(COM)元件和Microsoft Visual Basic
6.0执行时间动态连结函式库档案,如Vbrun500.dll和Msvbvm50.dll等。不要把这个目录放置在站台目录下,这样未被授权的使用者将可以存取企业或是个人的资讯。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">说明档<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
说明档是伺服器端内含的档案或文字档,它使HTML编码的资讯可以透过应用程式来使用。为了安全上的考量,这个目录不能存放在公开的Web空间内。</font></p>
<p><font face="arial" color="#3e72d7" size="4" style="line-height: 25px">
<b style="line-height: 25px">套用档案副档名标准<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
这部分显示了一些标准的档案副档名,包括指令档或是内含有 HTML和指令档的档案。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -