ASP. NET implements multi-domain name multi-site shared Session Value
1. Implementation function: You can set which sites can share the Session value, so as to prevent others from using this to access
To implement this function, you must put the Session value in the database. First, register
The name is as follows: aspnet_regsql.exe-S [database service address]-E-ssadd. For the specific format, refer /?
After successful addition, we need to make simple modifications to the stored procedure generated by ASP. NET,
Open ASP.net and find the stored procedure "TempGetAppID" for the database "ASPState" created for us"
Then modify the stored procedure as follows:
Copy codeThe Code is as follows:
USE [ASPState]
GO
/***** Object: StoredProcedure [dbo]. [TempGetAppID] Script Date: 11/21/2011 16:15:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
Alter procedure [dbo]. [TempGetAppID]
@ AppName tAppName,
@ AppId int OUTPUT
AS
SET @ appName = LOWER (@ appName)
SET @ appId = NULL
Set @ appId = 640732509 -- this is what I wrote when I tested it myself. You can query the site appId through ASPStateTempApplications in the system database tempdb. Remember that only when the Seeion configuration of the website is in the database and saved only one Session value can be queried
/*
-- SELECT @ appId = AppId
-- FROM [tempdb]. dbo. ASPStateTempApplications
-- WHERE AppName = @ appName
The above annotation method is automatically generated by the original ASP.net
*/
IF @ appId IS NULL BEGIN
BEGIN TRAN
SELECT @ appId = AppId
FROM [tempdb]. dbo. ASPStateTempApplications WITH (TABLOCKX)
WHERE AppName = @ appName
IF @ appId IS NULL
BEGIN
EXEC GetHashCode @ appName, @ appId OUTPUT
INSERT [tempdb]. dbo. ASPStateTempApplications
VALUES
(@ AppId, @ appName)
IF @ ERROR = 2627
BEGIN
DECLARE @ dupApp tAppName
SELECT @ dupApp = RTRIM (AppName)
FROM [tempdb]. dbo. ASPStateTempApplications
WHERE AppId = @ appId
RAISERROR ('SQL session state fatal error: hash-code collision between applications' % s' and '% s ''. please rename the 1st application to resolve the problem. ',
18, 1, @ appName, @ dupApp)
END
END
COMMIT
END
RETURN 0
This can be shared, but we have to solve the problem by replacing the SeeionID of the client. We can add a handler to use the SessionIDManager class for processing,
I will not write the instance, and I will write a replacement method for the value.
Copy codeThe Code is as follows:
SessionIDManager sessionid = new SessionIDManager ();
Bool;
Bool B;
Sessionid. SaveSessionID (this. Context, "Here is SeeionID", out a, out B );
Last modified configuration file
Add <sessionState mode = "SQLServer" sqlConnectionString = "data source = data connection; user id = sa; password = 123456;"> </sessionState> to the System. Web node.
Okay. You can try it.