Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 28, 2009 04:17 AM by saffy
Member
304 Points
365 Posts
Jan 27, 2009 05:39 AM|LINK
Hi,
1) How can I create Global application variables/sessions. in
global.asax file.at Appliccation start
2) how can I access that sessions at normal pages.
variable created at global.asax page should accessed by all users.
and
3) can I update global session through normal web page?
All-Star
78956 Points
13402 Posts
MVP
Jan 27, 2009 05:51 AM|LINK
Create a varaiable
Assign value
and store it in Session varaiable
Dim str as string = ""
Sesion("Data") = str
Jan 27, 2009 07:19 AM|LINK
solution
void Application_Start(object sender, EventArgs e) { // type one Application["ActiveUsers"] = 0; //type two System.Data.DataSet ds = new System.Data.DataSet(); ds.ReadXml(@"D:\..............\xmlfiles\tesdata.xml"); Application["ds"] = ds; }
////////////////
void Session_Start(object sender, EventArgs e) { Session.Timeout = 20; Application.Lock(); Application["ActiveUsers"] = System.Convert.ToInt32(Application["ActiveUsers"]) + 1; Application.UnLock(); }
/////////// void Session_End(object sender, EventArgs e) { Application.Lock(); Application["ActiveUsers"] = System.Convert.ToInt32(Application["ActiveUsers"]) - 1; Application.UnLock(); }
below is form code
//type one
Response.Write(Application["ActiveUsers"].ToString());
//type two
GridView1.DataSource =(DataSet)Application["ds"]; GridView1.DataBind();
Jan 27, 2009 07:22 AM|LINK
mudassarkhan Create a varaiable Assign value and store it in Session varaiable Dim str as string = "" Sesion("Data") = str
Can view use Session in global.asax,
I have used
Session["test11"]="Some value";
at run time it throws an error of
Session state is not available in this context.
should we configure in web.config file.
Jan 27, 2009 07:43 AM|LINK
use
httpcontext.Current .Session["test11"]="Some value";
130 Points
43 Posts
Jan 27, 2009 08:00 AM|LINK
When u use Application its scope is through all Sessions.
In case of Session its scope is limited to particular session. U can access it from any page of ur website in ur session only.
In case of Cache its scope is upto particular page.
Jan 27, 2009 08:10 AM|LINK
mudassarkhan use httpcontext.Current .Session["test11"]="Some value";
its not working in global.asax file.
as to my knowledge we can use "Application" in global.asax file,
But Session ! no Idea
Jan 27, 2009 08:21 AM|LINK
saffy its not working in global.asax file. as to my knowledge we can use "Application" in global.asax file, But Session ! no Idea
Yes it works I am using in one application in VB.Net
Try this
HttpContext
may be bcoz C# is case sensitive
Jan 27, 2009 09:15 AM|LINK
its an example
System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(Server.MapPath(Class1.ReturnPath())); System.Xml.XmlElement root = doc.DocumentElement; System.Xml.XmlNodeList nodes = root.SelectNodes("CustomerTable"); Hashtable hT = new Hashtable(); foreach (System.Xml.XmlNode node in nodes) { hT.Add(node["Name"].InnerText, node["Age"].InnerText); } Application["ds1"] = hT;
Jan 27, 2009 09:28 AM|LINK
mudassarkhan Yes it works I am using in one application in VB.Net Try this HttpContext.Current.Session["Test"] = "Value"; may be bcoz C# is case sensitive
HttpContext.Current.Session["Test"] = "Value";
am afraid its not working I am using C#.net and asp.net. for me Application is working, but not Session
saffy
Member
304 Points
365 Posts
Global.asax file sessions.
Jan 27, 2009 05:39 AM|LINK
Hi,
1) How can I create Global application variables/sessions. in
global.asax file.at Appliccation start
2) how can I access that sessions at normal pages.
variable created at global.asax page should accessed by all users.
and
3) can I update global session through normal web page?
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Global.asax file sessions.
Jan 27, 2009 05:51 AM|LINK
Create a varaiable
Assign value
and store it in Session varaiable
Dim str as string = ""
Sesion("Data") = str
Contact me
saffy
Member
304 Points
365 Posts
Re: Global.asax file sessions.
Jan 27, 2009 07:19 AM|LINK
solution
void Application_Start(object sender, EventArgs e)
{
// type one
Application["ActiveUsers"] = 0;
//type two
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(@"D:\..............\xmlfiles\tesdata.xml");
Application["ds"] = ds;
}
////////////////
void Session_Start(object sender, EventArgs e)
{
Session.Timeout = 20;
Application.Lock();
Application["ActiveUsers"] = System.Convert.ToInt32(Application["ActiveUsers"]) + 1;
Application.UnLock();
}
///////////
void Session_End(object sender, EventArgs e)
{
Application.Lock();
Application["ActiveUsers"] = System.Convert.ToInt32(Application["ActiveUsers"]) - 1;
Application.UnLock();
}
below is form code
//type one
Response.Write(Application["ActiveUsers"].ToString());
//type two
GridView1.DataSource =(DataSet)Application["ds"];
GridView1.DataBind();
saffy
Member
304 Points
365 Posts
Re: Global.asax file sessions.
Jan 27, 2009 07:22 AM|LINK
Can view use Session in global.asax,
I have used
Session["test11"]="Some value";
at run time it throws an error of
Session state is not available in this context.
should we configure in web.config file.
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Global.asax file sessions.
Jan 27, 2009 07:43 AM|LINK
use
httpcontext.Current .Session["test11"]="Some value";
Contact me
abhishekbhos...
Member
130 Points
43 Posts
Re: Global.asax file sessions.
Jan 27, 2009 08:00 AM|LINK
When u use Application its scope is through all Sessions.
In case of Session its scope is limited to particular session. U can access it from any page of ur website in ur session only.
In case of Cache its scope is upto particular page.
saffy
Member
304 Points
365 Posts
Re: Global.asax file sessions.
Jan 27, 2009 08:10 AM|LINK
its not working in global.asax file.
as to my knowledge we can use "Application" in global.asax file,
But Session ! no Idea
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Global.asax file sessions.
Jan 27, 2009 08:21 AM|LINK
Yes it works I am using in one application in VB.Net
Try this
HttpContext
.Current.Session["Test"] = "Value";may be bcoz C# is case sensitive
Contact me
saffy
Member
304 Points
365 Posts
HashTable in Application session
Jan 27, 2009 09:15 AM|LINK
its an example
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(Server.MapPath(Class1.ReturnPath()));
System.Xml.XmlElement root = doc.DocumentElement;
System.Xml.XmlNodeList nodes = root.SelectNodes("CustomerTable");
Hashtable hT = new Hashtable();
foreach (System.Xml.XmlNode node in nodes)
{
hT.Add(node["Name"].InnerText, node["Age"].InnerText);
}
Application["ds1"] = hT;
saffy
Member
304 Points
365 Posts
Re: Global.asax file sessions.
Jan 27, 2009 09:28 AM|LINK
am afraid its not working
I am using C#.net and asp.net.
for me Application is working, but not Session