Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am not able to access the session data. I want to access the data through
the SQLServer mode of session state. Also I m follows the following link

http://www.codeproject.com/Articles/27090/Sharing-Session-Across-Applications

What I have tried:

I have created two projects in same solution like SampleWeb and SampleWeb1
I want share the session data from SampleWeb to SampleWeb1
================================================================
In SampleWeb project added one form named as myWeb.aspx and on button click event I have added

protected void Button1_Click(object sender, EventArgs e)
{
Session["Name"] = TextBox1.Text;
Session["Email"] = TextBox2.Text;
Response.Redirect("~/MyWeb1.aspx");

}
================================================================
In SampleWeb1 project also added one form named as MyWeb1.aspx and I want to display the data from SampleWeb to SampleWeb1 project

protected void Page_Load(object sender, EventArgs e)
{

if (Session["name"] != null)
{
Lname.Text = Session["Name"].ToString();

}
if (Session["Email"] != null)
{
LEmail.Text = Session["Email"].ToString();
}
================================================================
also created one class in solution like ShareSessionModule
using System;
using System.Configuration;
using System.Reflection;
using System.web;
public class SharedSessionModule : IHttpModule
{

public void Init(HttpApplication context)
{
try
{
// Get the app name from config file...
string appName = ConfigurationManager.AppSettings["ApplicationName"];
if (!string.IsNullOrEmpty(appName))
{
FieldInfo runtimeInfo = typeof(HttpRuntime).GetField("_theRuntime",
BindingFlags.Static | BindingFlags.NonPublic);
HttpRuntime theRuntime = (HttpRuntime)runtimeInfo.GetValue(null);
FieldInfo appNameInfo = typeof(HttpRuntime).GetField("_appDomainAppId",
BindingFlags.Instance | BindingFlags.NonPublic);
appNameInfo.SetValue(theRuntime, appName);
}
}

}
=====================================================================
And finally in both web.config:
configuration

system.web

sessionstate mode="SQLServer" sqlconnectionstring="data source=INMU1D0121; user id=sa; password=sa; timeout=20" cookieless="false"
sessionstate
httpmodules
add name="SharedSessionModule" type="SharedSessionModule"
httpmodules

compilation debug="true" targetframework="4.5"
httpruntime targetframework="4.5"
system.web

appsettings>
add key="ApplicationName" value="SampleWeb"
appsettings

system.webserver
validation validateintegratedmodeconfiguration="false"
system.webserver
configuration

I want to known that I m going in right way or not.. and also I want to known
that the httpmodules tag is right or not
Thanks & regard
Ajay
Posted
Updated 8-May-16 23:53pm
v2
Comments
Sergey Alexandrovich Kryukov 9-May-16 10:00am    
Why?
—SA
AjaykumarD 9-May-16 23:55pm    
I m final year MCA student and I m doing an internship. so the company want to update their attendance system site without using the present website, so I want to share the session data of attendance site to another website application

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