Click here to Skip to main content
15,899,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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
HTML
<sessionstate>
      mode="SQLServer"
      sqlConnectionString="data source=.;integrated security=true">

    </sessionstate>

in web.config.

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

C#
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!!
Posted
Updated 7-Aug-13 9:28am
v3

You can not share the session between applications (without a hack).

Read the discussion on this link:

http://stackoverflow.com/questions/3292359/why-cant-i-share-session-state-between-2-web-apps-with-stateserver-what-am-i-m[^]
 
Share this answer
 
Comments
sagarthemaster 8-Aug-13 5:11am    
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q325056

Will there be any use if I change the metabase of IIS??? instance from 1 to 5?
Dholakiya Ankit 8-Aug-13 5:54am    
i did not see ur solution and directly written from link
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 then modified web.config as:-

XML
<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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900