Asp. NET implementation of multi-domain multi-site Sharing Session value
1, implementation function: You can set which sites can share session value, so as to prevent others to use this to access
To implement this function, you have to put the session value into the database, all of which we first register with the VS command tool
Named as follows: Aspnet_regsql.exe-s [database service address]-e-ssadd specific format please refer to/?
After the addition of success we have to make simple modifications to the stored procedures generated by ASP.net,
Open asp.net to find the stored procedure "Tempgetappid" for the database we created "ASPState"
Then modify the stored procedure as follows:
Copy Code code 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 was written on my own test. You can query to the site through aspstatetempapplications in the system database tempdb appId Remember that only if the seeion configuration of the site is in the database and save a session value to query the
/*
--select @appId = appId
--from [Tempdb].dbo. Aspstatetempapplications
--where AppName = @appName
The above annotation method is the original ASP.net automatically generated
*/
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 '%s ' ' and '%s '. Please rename the 1st application to resolve the problem. '
1, @appName, @dupApp)
End
End
COMMIT
End
return 0
This can be shared, but we have to solve a problem is to replace the client's Seeionid, we can add a handler to use the SessionIDManager class for processing,
Instance I'm not writing, I'm writing a replacement method
Copy Code code as follows:
SessionIDManager SessionID = new SessionIDManager ();
BOOL A;
BOOL B;
SessionID. Savesessionid (this. Context, "Here is Seeionid", out of A, out B);
Last modified configuration file
Add the <sessionstate mode= "SQL Server" sqlconnectionstring= data source= to the system.web node, user id=sa; password=123456; "></sessionState>
Okay, all right, you try it.