Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Access variable from Global asax to a asmx page

Access variable from Global asax to a asmx page

Scheduled Pinned Locked Moved C#
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ramdil
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • R ramdil

      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

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • K kubben

        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

        R Offline
        R Offline
        ramdil
        wrote on last edited by
        #3

        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

        K 1 Reply Last reply
        0
        • R ramdil

          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

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          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

          R 1 Reply Last reply
          0
          • K kubben

            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

            R Offline
            R Offline
            ramdil
            wrote on last edited by
            #5

            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

            K 1 Reply Last reply
            0
            • R ramdil

              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

              K Offline
              K Offline
              kubben
              wrote on last edited by
              #6

              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

              R 1 Reply Last reply
              0
              • K kubben

                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

                R Offline
                R Offline
                ramdil
                wrote on last edited by
                #7

                Thanks Ben.I was assigning application variable at the initialization part.when i assigned it in section where i want actually, i am getting the value.Any way thanks for your replies. Expecting a positive replies in future Thanks

                Regards DilipRam

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups