vb.net application.lock 用法
application的机制,application是对整个网站有效的,所有访问网站的人享用同一个application,这点是不同于session的
锁定后其他页面在同一时间就无法进行application的操作了,你可以用操作系统的pv元去理解
<%@ page language="vb" autoeventwireup="false" codefile="default.asp教程x.vb" inherits="_default" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>untitled page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
the page has been requested
<asp:label id="mylabel" runat="server" />
times!
</div>
</form>
</body>
</html>file: default.aspx.vb
partial class _default
inherits system.web.ui.pageprotected sub page_load(byval sender as object, _
byval e as system.eventargs) handles me.load
if application("pagecounter") >= 10 then
application.remove("pagecounter")
end if
if application("pagecounter") is nothing then
application("pagecounter") = 1
else
application.lock()
application("pagecounter") += 1
application.unlock()
end if
mylabel.text = application("pagecounter")
end sub
end class
lock和unlock是成对使用的,他们都是对整个网站有效,当lock释放的同时unlock锁钉信息,这是瞬间完成的,其实你就感觉不到.如果你一旦使用了lock他就会对你的整个网站控制.