Asp. NET implementation of multi-domain name multi-site Sharing Session Value Method _ Practical Skills

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.