热门搜索:Photoshop 平面设计 Linux Vista Windows ASP.NET qq word 病毒 XP Excel 标志设计 

ASP.NET的 Session 详解

来源:动态网站制作指南(读取中...) 2007-4-19 【字体: 】 切换为

<scriptrunat="server">

Sub Session_Add(sender As Object, e As EventArgs)

  Session("MySession") = text1.Value

  span1.InnerHtml = "Session data updated! <P>Your session contains: <font color=red>" & \

Session("MySession").ToString() & "</font>"

End Sub

 

Sub CheckSession(sender As Object, eAs EventArgs)

  If (Session("MySession")Is Nothing) Then

  span1.InnerHtml = "NOTHING, SESSION DATA LOST!"

  Else

  span1.InnerHtml = "Your session contains: <font color=red>" & \

Session("MySession").ToString() & "</font>"

End If

End Sub

</script>

<formrunat="server"id="Form2">

  <inputid="text1"type="text"runat="server"name="text1">

  <inputtype="submit"runat="server"OnServerClick="Session_Add"

  value="Add to Session State" id="Submit1"name="Submit1">

  <inputtype="submit"runat="server"OnServerClick="CheckSession"

  value="View Session State" id="Submit2"name="Submit2">

</form>

<hrsize="1">

<fontsize="6"><spanid="span1"runat="server" /></font>

 

这个SessionState.aspx的页面可以用来测试在当前的服务器上是否丢失了Session信息。

 

将服务器Session信息存储在进程中

让我们来回到Web.config文件的刚才那段段落中:

 

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>

当mode的值是InProc时,说明服务器正在使用这种模式。

 

这种方式和以前ASP中的模式一样,就是服务器将Session信息存储在IIS进程中。当IIS关闭、重起后,这些信息都会丢失。但是这种模式也有自己最大好处,就是性能最高。应为所有的Session信息都存储在了IIS的进程中,所以IIS能够很快的访问到这些信息,这种模式的性能比进程外存储 Session信息或是在SQL Server中存储Session信息都要快上很多。这种模式也是ASP.NET的默认方式。

上一页  [1] [2] [3] [4] [5] [6] 下一页

关注此文的读者还看过:
    用户评论
评论内容:不能超过100字,需审核,请自觉遵守互联网相关政策法规。
发表评论: 匿名发表 用户名: loading 位网友发表了评论 查看评论
(0/100)