SQL Server的"采用&QUOT两个不同的asp.net的解决方案之间共享会话值;模式 [英] Sharing session value between two different asp.net solutions using "SQL Server" mode

查看:89
本文介绍了SQL Server的"采用&QUOT两个不同的asp.net的解决方案之间共享会话值;模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是测试。我创建我存储在存储得到了在数据库中的会话文本框的值的文本框,并在第一个asp.net应用程序并在按钮事件的按钮。

I was just testing. I created a text box and a button in first asp.net application and on the button event i stored the value of text box in a session that got stored in database.

现在我创造了另一个asp.net应用程序只是一个文本框。现在,我想打电话给在第一asp.net应用程序的文本框中的值。

Now i created another asp.net application with just a text box. Now I want to call the value of the text box in the first asp.net application.

我会怎么做呢?

我已经阅读所有的理论应用。如果有人能写下来code它,那将是很大的帮助。

I have already read all the theoretical application. If someone could write down the code for it, it would be great help.

我用

<mode="SQLServer"
sqlConnectionString="data source=.;integrated security=true">

在web.config中。

in web.config.

我也成功创建SQL Server中的数据库ASPState的2008 R2。

I have also successfully created the ASPState database in SQL Server 2008 R2.

protected void Button1_Click(object sender, EventArgs e)
{
Session["mydb"] = TextBox1.Text;
}

我保存这样的文本框的值。其得到存储在数据库中根据表ASPStateTempSessions以加密的形式在柱的sessionid

I am storing value of textbox like this. Its getting stored in the database under table "ASPStateTempSessions" in encrypted form in column SessionId.

现在我没有得到如何调用存储在数据库中的文本框在我的第二web应用此值。

Now I am not getting how to call this value stored in database in the text box in my second web application.

我希望你明白我的问题。请帮助我!

I hope you understand my problem. Please help me!!

推荐答案

我已经找到了解决办法: -

I have found a solution:-

我只是改变了程序即。

USE ASPState
GO

ALTER PROCEDURE dbo.TempGetAppID
    @appName tAppName,
    @appId int OUTPUT
AS

    -- start change

    -- Use the application name specified in the connection for the appname if specified
    -- This allows us to share session between sites just by making sure they have the
    -- the same application name in the connection string.
    DECLARE @connStrAppName nvarchar(50)
    SET @connStrAppName = APP_NAME()

    -- .NET SQLClient Data Provider is the default application name for .NET apps
    IF (@connStrAppName <> '.NET SQLClient Data Provider')
        SET @appName = @connStrAppName

    -- end change

SET @appName = LOWER(@appName)
SET @appId = NULL

SELECT @appId = AppId
FROM [ASPState].dbo.ASPStateTempApplications
WHERE AppName = @appName

IF @appId IS NULL BEGIN
BEGIN TRAN 

SELECT @appId = AppId
FROM [ASPState].dbo.ASPStateTempApplications WITH (TABLOCKX)
WHERE AppName = @appName

IF @appId IS NULL
BEGIN
EXEC GetHashCode @appName, @appId OUTPUT

INSERT [ASPState].dbo.ASPStateTempApplications
VALUES
(@appId, @appName)

IF @@ERROR = 2627 
BEGIN
DECLARE @dupApp tAppName

SELECT @dupApp = RTRIM(AppName)
FROM [ASPState].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 
GO

和web.config中: -

and the web.config:-

<sessionState mode="SQLServer" sqlConnectionString="Data Source=.;Integrated Security=True;Application Name=TEST" cookieless="false" timeout="20"></sessionState>
   <httpRuntime targetFramework="4.5"/>

您必须添加应用程序名称和必须为所有要共享同一个会话的应用程序是相同的。

You have to add Application Name and that have to be the same for all the application for which you want to share the same session.

感谢。

这篇关于SQL Server的&QUOT;采用&QUOT两个不同的asp.net的解决方案之间共享会话值;模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆