1

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.

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.

How will I do it?

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

I have used

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

in web.config.

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;
}

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

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!!

3
  • 1
    possible duplicate of Sharing sessions across applications using the ASP.NET Session State Service Commented Aug 7, 2013 at 16:29
  • Session is not really supposed to be used like that. Also "someone could write down the code for it" is not really what SO is about. We'll help you, but we're not doing it for you. Commented Aug 7, 2013 at 17:26
  • Okay. Thanx for helping me but not doing it for me ^^. I am also trying if i found a solutions I will surely post it out here. Commented Aug 8, 2013 at 6:53

1 Answer 1

2

I have found a solution:-

I just changed the procedure i.e.

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

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.

Thanks.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I would like to pass the same value present in the key "Application Name" from connection string to my Temp GetAppID procedure, to make an if condition, is that possible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.