解决asp.net丢失session的方法文件
/* First uninstall - this section is exactly the same as uninstall.sql */
USE master
GO
/* Drop the database containing our sprocs */
IF DB_ID('ASPState') IS NOT NULL BEGIN
DROP DATABASE ASPState
END
GO
/* Drop temporary tables */
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name = 'ASPStateTempSessions' AND type = 'U') BEGIN
DROP TABLE tempdb..ASPStateTempSessions
END
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name = 'ASPStateTempApplications' AND type = 'U') BEGIN
DROP TABLE tempdb..ASPStateTempApplications
END
GO
/* Drop the startup procedure */
DECLARE @PROCID int
SET @PROCID = OBJECT_ID('ASPState_Startup')
IF @PROCID IS NOT NULL AND OBJECTPROPERTY(@PROCID, 'IsProcedure') = 1 BEGIN
DROP PROCEDURE ASPState_Startup
END
GO
/* Drop the obsolete startup enabler */
DECLARE @PROCID int
SET @PROCID = OBJECT_ID('EnableASPStateStartup')
IF @PROCID IS NOT NULL AND OBJECTPROPERTY(@PROCID, 'IsProcedure') = 1 BEGIN
DROP PROCEDURE EnableASPStateStartup
END
GO
/* Drop the obsolete startup disabler */
DECLARE @PROCID int
SET @PROCID = OBJECT_ID('DisableASPStateStartup')
IF @PROCID IS NOT NULL AND OBJECTPROPERTY(@PROCID, 'IsProcedure') = 1 BEGIN
DROP PROCEDURE DisableASPStateStartup
END
GO
/* Drop the ASPState_DeleteExpiredSessions_Job */
DECLARE @JobID BINARY(16)
SELECT @JobID = job_id
FROM msdb.dbo.sysjobs
WHERE (name = N'ASPState_Job_DeleteExpiredSessions')
IF (@JobID IS NOT NULL)
BEGIN
-- Check if the job is a multi-server job
IF (EXISTS (SELECT *
FROM msdb.dbo.sysjobservers
WHERE (job_id = @JobID) AND (server_id <> 0)))
BEGIN
-- There is, so abort the script
RAISERROR (N'Unable to import job ''ASPState_Job_DeleteExpiredSessions'' since there is already a multi-server job with this name.', 16, 1)
END
ELSE
-- Delete the [local] job
EXECUTE msdb.dbo.sp_delete_job @job_name = N'ASPState_Job_DeleteExpiredSessions'
END
USE master
GO
/* Create and populate the ASPState database */
CREATE DATABASE ASPState
GO
USE ASPstate
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE DropTempTables
AS
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name = 'ASPStateTempSessions' AND type = 'U') BEGIN
DROP TABLE tempdb..ASPStateTempSessions
END
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name = 'ASPStateTempApplications' AND type = 'U') BEGIN
DROP TABLE tempdb..ASPStateTempApplications
END
RETURN 0
GO
CREATE PROCEDURE CreateTempTables
AS
/*
* Note that we cannot create user-defined data types in
* tempdb because sp_addtype must be run in the context
* of the current database, and we cannot switch to
* tempdb from a stored procedure.
*/
CREATE TABLE tempdb..ASPStateTempSessions (
SessionId CHAR(32) NOT NULL PRIMARY KEY,
Created DATETIME NOT NULL DEFAULT GETDATE(),
Expires DATETIME NOT NULL,
LockDate DATETIME NOT NULL,
LockCookie INT NOT NULL,
Timeout INT NOT NULL,
Locked BIT NOT NULL,
SessionItemShort VARBINARY(7000) NULL,
SessionItemLong IMAGE NULL,
)
CREATE TABLE tempdb..ASPStateTempApplications (
AppId INT NOT NULL IDENTITY PRIMARY KEY,
AppName CHAR(280) NOT NULL,
)
CREATE NONCLUSTERED INDEX Index_AppName ON tempdb..ASPStateTempApplications(AppName)
RETURN 0
GO
CREATE PROCEDURE ResetData
AS
EXECUTE DropTempTables
EXECUTE CreateTempTables
RETURN 0
GO
EXECUTE sp_addtype tSessionId, 'CHAR(32)', 'NOT NULL'
GO
EXECUTE sp_addtype tAppName, 'VARCHAR(280)', 'NOT NULL'
GO
EXECUTE sp_addtype tSessionItemShort, 'VARBINARY(7000)'
GO
EXECUTE sp_addtype tSessionItemLong, 'IMAGE'
GO
EXECUTE sp_addtype tTextPtr, 'VARBINARY(16)'
GO
CREATE PROCEDURE TempGetAppId
@appName tAppName,
@appId INT OUTPUT
AS
SELECT @appId = AppId
FROM tempdb..ASPStateTempApplications
WHERE AppName = @appName
IF @appId IS NULL BEGIN
INSERT tempdb..ASPStateTempApplications
(AppName)
VALUES
(@appName)
SELECT @appId = AppId
FROM tempdb..ASPStateTempApplications
WHERE AppName = @appName
END
RETURN 0
GO
CREATE PROCEDURE TempGetStateItem
@id tSessionId,
@itemShort tSessionItemShort OUTPUT,
@locked BIT OUTPUT,
@lockDate DATETIME OUTPUT,
@lockCookie INT OUTPUT
AS
DECLARE @textptr AS tTextPtr
DECLARE @length AS INT
DECLARE @now as DATETIME
SET @now = GETDATE()
UPDATE tempdb..ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, @now),
@locked = Locked,
@lockDate = LockDate,
@lockCookie = LockCookie,
@itemShort = CASE @locked
WHEN 0 THEN SessionItemShort
ELSE NULL
END,
@textptr = CASE @locked
WHEN 0 THEN TEXTPTR(SessionItemLong)
ELSE NULL
END,
@length = CASE @locked
WHEN 0 THEN DATALENGTH(SessionItemLong)
ELSE NULL
END
WHERE SessionId = @id
IF @length IS NOT NULL BEGIN
READTEXT tempdb..ASPStateTempSessions.SessionItemLong @textptr 0 @length
END
RETURN 0
GO
CREATE PROCEDURE TempGetStateItemExclusive
@id tSessionId,
@itemShort tSessionItemShort OUTPUT,
@locked BIT OUTPUT,
@lockDate DATETIME OUTPUT,
@lockCookie INT OUTPUT
AS
DECLARE @textptr AS tTextPtr
DECLARE @length AS INT
DECLARE @now as DATETIME
SET @now = GETDATE()
UPDATE tempdb..ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, @now),
@lockDate = LockDate = CASE Locked
WHEN 0 THEN @now
ELSE LockDate
END,
@lockCookie = LockCookie = CASE Locked
WHEN 0 THEN LockCookie + 1
ELSE LockCookie
END,
@itemShort = CASE Locked
WHEN 0 THEN SessionItemShort
ELSE NULL
END,
@textptr = CASE Locked
WHEN 0 THEN TEXTPTR(SessionItemLong)
ELSE NULL
END,
@length = CASE Locked
WHEN 0 THEN DATALENGTH(SessionItemLong)
ELSE NULL
END,
@locked = Locked,
Locked = 1
WHERE SessionId = @id
IF @length IS NOT NULL BEGIN
READTEXT tempdb..ASPStateTempSessions.SessionItemLong @textptr 0 @length
END
RETURN 0
GO
CREATE PROCEDURE TempReleaseStateItemExclusive
@id tSessionId,
@lockCookie INT
AS
UPDATE tempdb..ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, GETDATE()),
Locked = 0
WHERE SessionId = @id AND LockCookie = @lockCookie
RETURN 0
GO
CREATE PROCEDURE TempInsertStateItemShort
@id tSessionId,
@itemShort tSessionItemShort,
@timeout INT
AS
DECLARE @now as DATETIME
SET @now = GETDATE()
INSERT tempdb..ASPStateTempSessions
(SessionId,
SessionItemShort,
Timeout,
Expires,
Locked,
LockDate,
LockCookie)
VALUES
(@id,
@itemShort,
@timeout,
DATEADD(n, @timeout, @now),
0,
@now,
1)
RETURN 0
GO
CREATE PROCEDURE TempInsertStateItemLong
@id tSessionId,
@itemLong tSessionItemLong,
@timeout INT
AS
DECLARE @now as DATETIME
SET @now = GETDATE()
INSERT tempdb..ASPStateTempSessions
(SessionId,
SessionItemLong,
Timeout,
Expires,
Locked,
LockDate,
LockCookie)
VALUES
(@id,
@itemLong,
@timeout,
DATEADD(n, @timeout, @now),
0,
@now,
1)
RETURN 0
GO
CREATE PROCEDURE TempUpdateStateItemShort
@id tSessionId,
@itemShort tSessionItemShort,
@timeout INT,
@lockCookie INT
AS
UPDATE tempdb..ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, GETDATE()),
SessionItemShort = @itemShort,
Timeout = @timeout,
Locked = 0
WHERE SessionId = @id AND LockCookie = @lockCookie
RETURN 0
GO
CREATE PROCEDURE TempUpdateStateItemShortNullLong
@id tSessionId,
@itemShort tSessionItemShort,
@timeout INT,
@lockCookie INT
AS
UPDATE tempdb..ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, GETDATE()),
SessionItemShort = @itemShort,
SessionItemLong = NULL,
Timeout = @timeout,
Locked = 0
WHERE SessionId = @id AND LockCookie = @lockCookie
RETURN 0
GO
CREATE PROCEDURE TempUpdateStateItemLong
@id tSessionId,
@itemLong tSessionItemLong,
@timeout INT,
@lockCookie INT
AS
UPDATE tempdb..ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, GETDATE()),
SessionItemLong = @itemLong,
Timeout = @timeout,
Locked = 0
WHERE SessionId = @id AND LockCookie = @lockCookie
RETURN 0
GO
CREATE PROCEDURE TempUpdateStateItemLongNullShort
@id tSessionId,
@itemLong tSessionItemLong,
@timeout INT,
@lockCookie INT
AS
UPDATE tempdb..ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, GETDATE()),
SessionItemLong = @itemLong,
SessionItemShort = NULL,
Timeout = @timeout,
Locked = 0
WHERE SessionId = @id AND LockCookie = @lockCookie
RETURN 0
GO
CREATE PROCEDURE TempRemoveStateItem
@id tSessionId,
@lockCookie INT
AS
DELETE tempdb..ASPStateTempSessions
WHERE SessionId = @id AND LockCookie = @lockCookie
RETURN 0
GO
CREATE PROCEDURE TempResetTimeout
@id tSessionId
AS
UPDATE tempdb..ASPStateTempSessions
SET Expires = DATEADD(n, Timeout, GETDATE())
WHERE SessionId = @id
RETURN 0
GO
CREATE PROCEDURE DeleteExpiredSessions
AS
DECLARE @now DATETIME
SET @now = GETDATE()
DELETE tempdb..ASPStateTempSessions
WHERE Expires < @now
RETURN 0
GO
EXECUTE CreateTempTables
GO
/* Create the startup procedure */
USE master
GO
CREATE PROCEDURE ASPState_Startup
AS
EXECUTE ASPState..CreateTempTables
RETURN 0
GO
EXECUTE sp_procoption @procname='ASPState_Startup', @optionname='startup', @optionvalue='true'
/* Create the job to delete expired sessions */
BEGIN TRANSACTION
DECLARE @JobID BINARY(16)
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
-- Add job category
IF (SELECT COUNT(*) FROM msdb.dbo.syscategories WHERE name = N'[Uncategorized (Local)]') < 1
EXECUTE msdb.dbo.sp_add_category @name = N'[Uncategorized (Local)]'
-- Add the job
EXECUTE @ReturnCode = msdb.dbo.sp_add_job
@job_id = @JobID OUTPUT,
@job_name = N'ASPState_Job_DeleteExpiredSessions',
@owner_login_name = NULL,
@description = N'Deletes expired sessions from the session state database.',
@category_name = N'[Uncategorized (Local)]',
@enabled = 1,
@notify_level_email = 0,
@notify_level_page = 0,
@notify_level_netsend = 0,
@notify_level_eventlog = 0,
@delete_level= 0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the job steps
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep
@job_id = @JobID,
@step_id = 1,
@step_name = N'ASPState_JobStep_DeleteExpiredSessions',
@command = N'EXECUTE DeleteExpiredSessions',
@database_name = N'ASPState',
@server = N'',
@database_user_name = N'',
@subsystem = N'TSQL',
@cmdexec_success_code = 0,
@flags = 0,
@retry_attempts = 0,
@retry_interval = 1,
@output_file_name = N'',
@on_success_step_id = 0,
@on_success_action = 1,
@on_fail_step_id = 0,
@on_fail_action = 2
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXECUTE @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the job schedules
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschedule
@job_id = @JobID,
@name = N'ASPState_JobSchedule_DeleteExpiredSessions',
@enabled = 1,
@freq_type = 4,
@active_start_date = 20001016,
@active_start_time = 0,
@freq_interval = 1,
@freq_subday_type = 4,
@freq_subday_interval = 1,
@freq_relative_interval = 0,
@freq_recurrence_factor = 0,
@active_end_date = 99991231,
@active_end_time = 235959
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the Target Servers
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO
解决asp.net丢失session的方法文件的更多相关文章
- 几种判断asp.net中session过期方法的比较
方法一:最麻烦也是最容易想到的方法,在每个页面的page_load()方法里面判断: protected void Page_Load(object sender, EventArgs e) { if ...
- 解决asp.net mvc中*.resx资源文件访问报错
个人笔记 问题重现 在asp.net mvc中,使用资源文件会出现一个问题,例如: 紧接着我进入视图界面,输入下面代码: <a href="javascript:void(0);&qu ...
- 判断asp.net中session过期方法的比较
重写继承page的OnInit()虚方法,在需要的界面上,继承这个类. 1.新建继承page类的类JudgeSession,实现接口成员. 2.重写OnInit()方法,判断session情况. 3. ...
- 解决 asp.net core 中下载 exe 文件返回 404
在 StartUp 中的 Configure 方法添加如下代码即可 app.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = ...
- Asp.Net保存session的三种方法 (Dll文件更新导致session丢失的解决办法)
1. InProc模式(默认值):asp.net将session保存到当前进程中,这种方式最快,但是不能多台服务器共享session,且会话状态数据容易丢失. <sessionState mod ...
- ASP.Net MVC_DotNetZip简单使用方法,解决文件压缩的问题[转]
准备工作: 在vs工具栏中找到NuGet 下载DotNetZip 现在就可以使用DotNetZip强大的类库了,在这里我给出一些简单的使用. ? 1 2 3 4 5 6 7 8 9 10 11 ...
- asp.net限制了上传文件大小为..M,解决方法
asp.net限制了上传文件大小为4M,在:在web.config里加下面一句,加在<System.web></System.web>之间如下:<system.web&g ...
- 彻底解决asp.net mvc5.2.2:vs2013 cshtml视图文件报错(当前上下文中不存在名称“model”,ViewBag,Url)
最近遇到一个奇葩的问题,在vs2013下cshtml视图文件报错,出现当前上下文中不存在名称“model”,ViewBag,Url等等),在视图中也没有智能提示了,用@model声明视图的model类 ...
- 判断asp.net中session过期的方法
判断asp.net中session过期的方法 转载自:http://www.cnblogs.com/xilipu31/archive/2013/04/12/3016830.html 方法一:最麻烦也是 ...
随机推荐
- [前端] AJAX
背景 Asynchronous JavaScript And XML:异步js和XML,可实现异步刷新 用途 验证提交的用户名是否已存在 不使用AJAX,需要提交数据后,刷新页面来验证 使用AJAX, ...
- CentOS、RHEL、Asianux、Neokylin、湖南麒麟、BC Linux、普华、EulerOS请参考“1.1 CentOS本地源配置”;
本文档适用于CentOS.RHEL.Asianux.Neokylin.湖南麒麟.BC Linux.普华.EulerOS.SLES.Ubuntu.Deepin.银河麒麟. CentOS.RHEL.A ...
- 使用sosreport命令生成诊断包
[RHEL]-7-常用系统状态检测命令 引言 这篇文章介绍RHEL中最常用的几个系统状态检测命令,包括:网络状态.内存.主机名及其架构.系统负载及其用户登录状态等. 文章目录 0×1.查看网络状态 0 ...
- echo -n -e "请输入重启间隔的时间(分钟):\t"
echo -n -e "请输入重启间隔的时间(分钟):\t"read interval##echo -n "Your choice is " # 加上 -n 可 ...
- kvm总结复习
一.虚拟化概念 1.虚拟化技术:在计算机技术中,虚拟化(技术)或虚拟技术(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源(CPU.内存.磁盘空间.网络适配器等),予以 ...
- IT菜鸟之交换机基础配置
交换机属于二层设备(隶属于osi七层模型中的第二层:数据链路层,不识别不支持IP地址) > 用户模式 用于登录设备 # 特权模式 用于查询设备配置 (config)# 全局模式 用于配置设备 ...
- SPI总线 通俗易懂讲解——(转载)
SPI总线 MOTOROLA公司的SPI总线的基本信号线为3根传输线,即SI.SO.SCK.传输的速率由时钟信号SCK决定,SI为数据输入.SO为数据输出.采用SPI总线的系统如图8-27所示,它包含 ...
- STM32的三种启动方式
- centos7网卡配置文件详解与固定服务器ip
环境:Centos7.3(最小安装方式安装) 查看自动获取的IP地址 ip addr 更改网卡配置,配置静态IP 网卡配置文件位置:/etc/sysconfig/network-scripts/ifc ...
- nginx反向代理网站镜像
某些公司会墙特定网站,如果你有一个可访问的域名和服务器,就可以通过nginx反向代理来来解决这些问题.比如现在我们用mirror.example.com镜像www.baidu.com,以下是详细操作. ...