dd

ASP Server 对象


Server 对象用于访问有关服务器的属性和方法。

Server 对象

ASP Server 对象用于访问有关服务器的属性和方法。其属性和方法描述如下:

属性

属性描述
ScriptTimeout设置或返回在一段脚本终止前它所能运行时间(秒)的最大值。

方法

方法描述
CreateObject创建对象的实例。
Execute从另一个 ASP 文件中执行一个 ASP 文件。
GetLastError()返回可描述已发生错误状态的 ASPError 对象。
HTMLEncode把 HTML 编码应用到某个指定的字符串。
MapPath把一个指定的路径映射到一个物理路径。
Transfer把一个 ASP 文件中创建的所有信息发送(传输)到另一个 ASP 文件。
URLEncode把 URL 编码规则应用到指定的字符串。

在线实例

此文件最后被修改的时间是?
探测文件的最后修改时间。

<!DOCTYPE html>
<html>
<body>

<%
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set rs = fs.GetFile(Server.MapPath("demo_lastmodified.asp"))
modified = rs.DateLastModified
%>
This file was last modified on: <%response.write(modified)
Set rs = Nothing
Set fs = Nothing
%>

</body>
</html>

打开并读取某个文本文件
打开文件 "Textfile.txt" 以供读取。

<!DOCTYPE html>
<html>
<body>

<%
Set FS = Server.CreateObject("Scripting.FileSystemObject")
Set RS = FS.OpenTextFile(Server.MapPath("text") & "\TextFile.txt",1)
While not rs.AtEndOfStream
      Response.Write RS.ReadLine
      Response.Write("<br>")
Wend 
%>

<p>
<a href="text/textfile.txt"><img src="/images/btn_view_text.gif"></a>
</p>

</body>
</html>

自制的点击计数器

<%
Set FS=Server.CreateObject("Scripting.FileSystemObject")
Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 1, False)
fcount=RS.ReadLine
RS.Close

fcount=fcount+1

'This code is disabled due to the write access security on our server:
'Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 2, False)
'RS.Write fcount
'RS.Close

Set RS=Nothing
Set FS=Nothing

%>
<!DOCTYPE html>
<html>
<body>
<p>
This page has been visited <%=fcount%>  times.
</p>
</body>
</html>