ASP. NET implements multi-domain name multi-site shared Session Value

Source: Internet
Author: User

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 modify the stored procedure generated by ASP. NET. Open ASP.net and find the stored procedure "TempGetAppID" for the database "ASPState" we created"

Then modify the stored procedure as follows:

Copy to ClipboardReference: [www.bkjia.com] 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

The database can be queried only when the Session value is saved once.
/*
-- 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 to ClipboardReference: [www.bkjia.com] 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.

Advertisement: QQ Group of the Golden ocean natural framework open-source community: 82598514. I hope you can provide more support.

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.