app教程网 综合百科 asp.net sessionid(asp.net session用法)

asp.net sessionid(asp.net session用法)

asp.NET的Session的存储方式不像ASP那么简单,它提供了三种存储方式。由于最近一个超过2000人使用的web软件出现故障,用户很难在每天早上的某个时间登录。

那么会话就失去了价值,只有重启IIS,或者机器。这时,程序恢复正常。同样的问题一天都不会出现,但是第二天还是一样!这种现象持续了好几天。我查了一下日志文件,发现峰值的时候大概是每秒20个访客。

同时在线的有100人左右,以后访问量还会增加。为了解决这个奇怪的问题,要从软件入手,所以三种方法都适用。

Open Web Profile Session Status

mode='InProc'

stateConnectionString='tcpip=127.0.0.1:42424'

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

cookieless='false'

timeout='20'

/

默认模式为InProc类型,与之前的ASP模式相同,即服务器将会话信息存储在IIS进程中,IIS关闭重启时这些进程信息会丢失,但这种模式性能最高(具体来说,

根据这本书),这种模式是ASP.NET的默认模式。

因为这种模式崩溃了,我当时的考虑是Inetinfo.exe进程由于过多的访问而崩溃。用户登录困难,导致会话丢失失败。

我使用了Session的另一种存储方法来存储进程外的会话信息。

首先,打开管理工具找到服务,找到名为ASP.NET国家服务的服务,启动它,并将其更改为自动启动。此时,您可以在任务管理器中看到一个名为aspnet_state.exe的进程。

这是我们保存会话信息的方式。

然后,返回到web.config文件,将Mode的值更改为StateServer,并保存该文件。好的。

sessionState

mode='StateServer'

stateConnectionString='tcpip=127.0.0.1:42424'

sqlConnectionString='data source=192.10.78.76;User id=sa;password=sa'

cookieless='false'

timeout='20'

/

此模式下当我们重启IIS时,保存的会话值不会丢失。此外,这种方式还可以保存其他机器过程中的信息,

但是,需要更改StateConnectionString=' tcpip=127 . 0 . 0 . 1:42424 '并将ip地址更改为其他机器。

此外,还采取了其他措施,如将数据库与WEB服务器分离,Web服务器不提供Web服务,Web服务器不提供数据库服务。

然后扩展了连接池。由于ASP.NET ADO.NET数据访问的连接池默认数量是100,我后来将其扩展到6000,并顺便添加了写入方法。

"Server=(local);

Database=rgs;

password=sa;

user ID=sa;

Max Pool Size=6000;

Min Pool Size=5;

Collection=true "

最后,Machine.config中ProcessModel中的memoryLimit改为95,默认值为60,这意味着iis进程在内存使用率超过60%后会自动重启。然后写一些其他的方法来优化IIS,

增加注册表的IIS缓存等等。

当我完成这些优化步骤后,整个软件运行良好,第二天没有发现堵塞的情况,但是第二天情况又出现了,我真的无能为力。

我采用了ASP.NET session的最后一种存储方式,就是将Session存储在SQLServer中。我觉得应该更稳定。

Run InstallSqlState.sql or InstallPersistSqlState.sql (default location: systemroot\Microsoft. NET \ Framework \ version number) both scripts create a database named ASPState, and the difference between the two scripts lies in the location where the ASPStateTempApplication and ASPStageTempSessions tables are placed.

Then, in the webpage configuration file of the application, set the mode attribute of the session state element as SQLServer, and finally set the sqlConnectionString attribute as comprehensive security=SSPI; Data source=server name;

sessionState mode='SQLServer' sqlConnectionString=' Integrated Security=SSPI;

data source=dataserver;'

cookieless='false'

timeout='20'/

/sessionState

如果它部署在其他计算机上,可以将其更改为,加上用户名和密码。

sessionState

mode='SQLServer'

stateConnectionString='tcpip=127.0.0.1:42424'

sqlConnectionString='data source=192.10.78.76;User id=sa;password=sa'

cookieless='false'

timeout='20'

/

只要在相应的目录(systemroot\Microsoft .NET\Framework\versionNumber)找到UninstallPersistSqlState.sql或者UninstallSqlState.sql文件运行即可。

最后需要注意的是,在使用StateServer或者SQLServer模式的时候,使用session来转换对象的时候,需要注意的是要先序列化对象,也就是在类之前加上Serializable,否则会出错!

本文来自网络,不代表本站立场,转载请注明出处:https: