Access variable from Global asax to a asmx page
-
Hi all I want to access variables declared in the global asax page to a asmx page. I declared variables as static public and then in asmx page i accessed it as global.variable name..but i am not getting value assinged to it..Can any one give me a idea why its not getting values in the variable Advance in thanks
Regards DilipRam
-
Hi all I want to access variables declared in the global asax page to a asmx page. I declared variables as static public and then in asmx page i accessed it as global.variable name..but i am not getting value assinged to it..Can any one give me a idea why its not getting values in the variable Advance in thanks
Regards DilipRam
Probabaly need to see your code, but it is a really bad idea to use a static var in global.asax. If you have an application wide varible you should use the application object, it is just like session. It can be set in an event in the global.asax or anywhere else for that matter. If the var is supose to be user specific then you need to use the session object. Ben
-
Probabaly need to see your code, but it is a really bad idea to use a static var in global.asax. If you have an application wide varible you should use the application object, it is just like session. It can be set in an event in the global.asax or anywhere else for that matter. If the var is supose to be user specific then you need to use the session object. Ben
Hi Thanks for the reply.Here is the part of my code. XMLCacheComm = new XMLCacheComm(); In Application_Start of global asax page Application["XMLCacheComm"] = XMLCacheComm; and in constructor XMLSportsIn() of webservice written as XMLCacheComm XMLCacheComm1 = Application["XMLCacheComm"] as XMLCacheComm; and in a method of webservice,when i call XMLCacheComm1.SendMessage()..here i am getting object reference not set to an instance of an object Any idea
Regards DilipRam
-
Hi Thanks for the reply.Here is the part of my code. XMLCacheComm = new XMLCacheComm(); In Application_Start of global asax page Application["XMLCacheComm"] = XMLCacheComm; and in constructor XMLSportsIn() of webservice written as XMLCacheComm XMLCacheComm1 = Application["XMLCacheComm"] as XMLCacheComm; and in a method of webservice,when i call XMLCacheComm1.SendMessage()..here i am getting object reference not set to an instance of an object Any idea
Regards DilipRam
When you create it in the application_start you have to assign it a variable XMLCacheComm _xmlCacheComm= new XMLCacheComm(); In Application_Start of global asax page Application["XMLCacheComm"] = _xmlCacheComm; This line: XMLCacheComm XMLCacheComm1 = Application["XMLCacheComm"] as XMLCacheComm; You might want to double check to see if the item is there. Something like: if (Application["XMLCacheComm"] != null) { XMLCacheComm XMLCacheComm1 = Application["XMLCacheComm"] as XMLCacheComm; } else { XMLCacheComm _xmlCacheComm= new XMLCacheComm(); Application["XMLCacheComm"] = _xmlCacheComm; } Hope that helps. Ben
-
When you create it in the application_start you have to assign it a variable XMLCacheComm _xmlCacheComm= new XMLCacheComm(); In Application_Start of global asax page Application["XMLCacheComm"] = _xmlCacheComm; This line: XMLCacheComm XMLCacheComm1 = Application["XMLCacheComm"] as XMLCacheComm; You might want to double check to see if the item is there. Something like: if (Application["XMLCacheComm"] != null) { XMLCacheComm XMLCacheComm1 = Application["XMLCacheComm"] as XMLCacheComm; } else { XMLCacheComm _xmlCacheComm= new XMLCacheComm(); Application["XMLCacheComm"] = _xmlCacheComm; } Hope that helps. Ben
-
Hi Thanks for the reply.I got out the object error.but i am not getting values inside it..inside the global i will get the count as 2 but inside webservice its count is getting as 1...why is this happening
Regards DilipRam
T
-
I am not that familar with the XMLCacheComm object, so I am not sure what the Count property refers to. So I am not sure why the count would be 1 or 2. Ben