65.9K
CodeProject 正在变化。 阅读更多。
Home

ASP 会话信息(经典)

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1投票)

2009年2月27日

CPOL
viewsIcon

29645

downloadIcon

328

查看经典 ASP 内存的内容

引言

当我被要求解决经典 ASP 应用程序的问题时,我首先做的事情是编写一个脚本,以便查看内存的内容。

这允许我在应用程序的任何阶段查看所有会话变量、cookie 等的确切副本。我倾向于将应用程序放在一个标签页中,将会话信息脚本放在另一个标签页中,并在导航应用程序时刷新。

我终于整理出一个可重用的脚本,想和大家分享。

ServerVariables.jpg - Click to enlarge image

Render 函数

渲染一个 HTML 表格,其中包含 oCollection 参数的内容

Function RenderTOC(sTitle, oCollection)
	Tab		= Chr(9)
	NewLine = Chr(13)

	If IsObject(oCollection) Then
		If (oCollection.Count>0) Then
			Response.Write(NewLine & "<table>" & NewLine)
			Response.Write(Tab & "<caption>" & sTitle & _
						"</caption>" & NewLine)
			Response.Write(Tab & "<thead>" & NewLine)
			Response.Write(Tab & Tab & "<tr><th>Name</th>_
				<th>Type</th><th>Value</th></tr>" & NewLine)
			Response.Write(Tab & "</thead>" & NewLine)
			Response.Write(Tab & "<tbody>" & NewLine)
			For Each D in oCollection
				If (d<>"") And (oCollection(d)<>"") Then
					Response.Write(Tab & Tab)
					Response.Write("<tr>")
					Response.Write("<th>" & _
						Server.HTMLencode(d) & "</th>")
					Response.Write("<td>" & TypeName(d) & _
						"</td>")
					Response.Write("<td>" & _
					    Server.HTMLencode(oCollection(d))_
					     & "</td>")
					Response.Write("</tr>")
					Response.Write(NewLine)
				End If
			Next
			Response.Write(Tab & "</tbody>" & NewLine)
			Response.Write("</table>" & NewLine)
		End If
	End If	
End Function

Using the Code

'  render contents of Request.Application
Call RenderTOC("Application Variables", Application.Contents)

' render contents of Request.Cookies
Call RenderTOC("Cookies", Request.Cookies)

' render contents of Request.SessionVariables
Call RenderTOC("Server Variables", Request.ServerVariables)

' render contents of Request.Form 
Call RenderTOC("Form Collection", Request.Form)

' render contents of Request.Querystring
Call RenderTOC("Querystring Collection", Request.Querystring)

' render contents of Session collection
Call RenderTOC("Session Variables", Session.Contents)

请务必谨慎!

重要的是不要将此脚本上传到生产服务器并忘记它,因为它会暴露敏感信息(数据库连接字符串等)。

我附上了一个 ASP 脚本,您可以将其放到您的服务器上,调整可访问的 IP 地址,然后就可以使用了!

历史

  • 2009年2月27日:初始发布
© . All rights reserved.