【发布时间】:2011-12-08 06:46:37
【问题描述】:
我是第一次尝试使用会话,想以一种更好、更简单的方式了解这一点。
我正在使用 GUID 创建一个会话变量,并使用该 GUID 创建一个文件夹并存储该值,如下所示
If Session("tempDir") Is Nothing Then
Dim tempDir As String
tempDir = Path.GetRandomFileName()
tempDir = tempDir.Substring(0, tempDir.LastIndexOf("."))
IO.Directory.CreateDirectory(Server.MapPath("Uploads/" & tempDir))
IO.Directory.CreateDirectory(Server.MapPath("Downloads/" & tempDir))
Session.Add("tempDir", tempDir)
currentDirectory.Value = Session("tempDir").ToString
CopySession.Text = currentDirectory.Value
End If
这是生成GUID的代码:
function randomString(length) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
if (!length) {
length = Math.floor(Math.random() * chars.length);
}
var str = '';
for (var i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * chars.length)];
}
return str;
}
我使用下面的代码在页面上获取回发但每当我刷新它时都会删除该值并给我一个 NULL 值。
If Page.IsPostBack Then
If Session("tempDir") Is Nothing Then
Dim tempDir As String
tempDir = Path.GetRandomFileName()
tempDir = tempDir.Substring(0, tempDir.LastIndexOf("."))
IO.Directory.CreateDirectory(Server.MapPath("Uploads/" & tempDir))
IO.Directory.CreateDirectory(Server.MapPath("Downloads/" & tempDir))
Session.Add("tempDir", tempDir)
currentDirectory.Value = Session("tempDir").ToString
CopySession.Text = currentDirectory.Value
End If
End If
我如何retrieve tempDir 值?谁能给我一些详细的解释,因为我完全糊涂了。
【问题讨论】: