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. Web Development
  3. ASP.NET
  4. Help in Converting Desktop App to Web App.

Help in Converting Desktop App to Web App.

Scheduled Pinned Locked Moved ASP.NET
csharpvisual-studiowcfsecurity
13 Posts 3 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.
  • Q QuickBooksDev

    Thanks I understand that there is no magic and no converter and that each page is new and any variables should be as initialized when built or saved in either viewState, SessionState, ApplicationState a cookie or other external source. This does not explain why variables in the 2nd VB class (vbServHandler) has new data in it while the 1st (vbMain) does not. What would cause this?

    Richard DeemingR Offline
    Richard DeemingR Offline
    Richard Deeming
    wrote on last edited by
    #4

    It sounds like vbServHandler is using Shared fields. You should generally avoid Shared fields in ASP.NET applications unless you really know what you're doing. For example, the data in the fields will be shared across all requests from all users, which means you could easily end up showing data meant for user A to user B by mistake.


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

    Q 1 Reply Last reply
    0
    • Richard DeemingR Richard Deeming

      It sounds like vbServHandler is using Shared fields. You should generally avoid Shared fields in ASP.NET applications unless you really know what you're doing. For example, the data in the fields will be shared across all requests from all users, which means you could easily end up showing data meant for user A to user B by mistake.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      Q Offline
      Q Offline
      QuickBooksDev
      wrote on last edited by
      #5

      They are NOT shared. I think it may be when a button control is hit on the page that the vbServHander is not getting re-initialized (vbServHandler variables still have data). I have done this: 1. By just click in the upload button on the vbMain button multiple times. 2. Clicking on the C# menu button (Upload) to reload the page. 3. Going back to the main page and clicking on the Upload button to reload the upload page. 4. Even refreshing the main home page via F5. In all cases the constructor for vbMain (i.e. sub new) shows data in the vbServHandler variables. I am programming around this (I actually think it is better) but just do not understand it.

      Richard DeemingR 1 Reply Last reply
      0
      • Q QuickBooksDev

        They are NOT shared. I think it may be when a button control is hit on the page that the vbServHander is not getting re-initialized (vbServHandler variables still have data). I have done this: 1. By just click in the upload button on the vbMain button multiple times. 2. Clicking on the C# menu button (Upload) to reload the page. 3. Going back to the main page and clicking on the Upload button to reload the upload page. 4. Even refreshing the main home page via F5. In all cases the constructor for vbMain (i.e. sub new) shows data in the vbServHandler variables. I am programming around this (I actually think it is better) but just do not understand it.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #6

        If the variables are persisted between requests to your site, and they're not stored in application or session state, then either they're stored in Shared fields, or the instance of the containing class is stored in a Shared field somewhere.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        Q 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          If the variables are persisted between requests to your site, and they're not stored in application or session state, then either they're stored in Shared fields, or the instance of the containing class is stored in a Shared field somewhere.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          Q Offline
          Q Offline
          QuickBooksDev
          wrote on last edited by
          #7

          They are not saved anywhere. If they are in some shared object then I do not know where it could be. Here is the definition of the object I was checking in the Sub new of vbMain. Public AccountCollection As Collection in what I was calling vbServHandler. Real name is QBAPIV3Cl which is part of DLL QBAPIV3VS2013. This is invoked via by vbMain Imports QBOAPIV3VS2013 . . Public aQB As New QBOAPIV3VS2013.QBAPIV3Cl() which is defined in a module within vbMain. . . Which is referenced by the C# Web App using vbMainDLL; In the C# program it is defined as vbMainDLL.vbMain vbMain; vbMain = new vbMain(TheRealmID,TheAccessToken,TheAccessTokenSecret, TheConsumerKey,TheConsumerSecret, TheContext,TheDataService, pOutReason: ref pOutReason); The Sub New for vbMain has aQB.accountcollection.count Referenced object has a value of nothing the first time. then 121 every other time. I would expect a value of nothing each time. The c# program has no references to the aQB class/QBOAPIV3VS2013.QBAPIV3Cl. So what am I missing?

          Richard DeemingR 1 Reply Last reply
          0
          • Q QuickBooksDev

            They are not saved anywhere. If they are in some shared object then I do not know where it could be. Here is the definition of the object I was checking in the Sub new of vbMain. Public AccountCollection As Collection in what I was calling vbServHandler. Real name is QBAPIV3Cl which is part of DLL QBAPIV3VS2013. This is invoked via by vbMain Imports QBOAPIV3VS2013 . . Public aQB As New QBOAPIV3VS2013.QBAPIV3Cl() which is defined in a module within vbMain. . . Which is referenced by the C# Web App using vbMainDLL; In the C# program it is defined as vbMainDLL.vbMain vbMain; vbMain = new vbMain(TheRealmID,TheAccessToken,TheAccessTokenSecret, TheConsumerKey,TheConsumerSecret, TheContext,TheDataService, pOutReason: ref pOutReason); The Sub New for vbMain has aQB.accountcollection.count Referenced object has a value of nothing the first time. then 121 every other time. I would expect a value of nothing each time. The c# program has no references to the aQB class/QBOAPIV3VS2013.QBAPIV3Cl. So what am I missing?

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #8

            QuickBooksDev wrote:

            which is defined in a module within vbMain.

            A Module is effectively a class in which every member is Shared. If your fields are stored in a Module, they they're Shared by definition.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            Q 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              QuickBooksDev wrote:

              which is defined in a module within vbMain.

              A Module is effectively a class in which every member is Shared. If your fields are stored in a Module, they they're Shared by definition.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              Q Offline
              Q Offline
              QuickBooksDev
              wrote on last edited by
              #9

              Here is the class Public Class QBAPIV3Cl ... No Module Public AccountCollection As Collection AccountCollection is the variable that I am checking for persistence. It is references by the vbMain module as Module Common which is a separate vb source file. Module Common .. Public aCL As New vbMain.QBAPIV3Cl() So what you are saying since MODULE common is a MODULE everything in it is Shared/Static including all of aCL????

              Richard DeemingR 1 Reply Last reply
              0
              • Q QuickBooksDev

                Here is the class Public Class QBAPIV3Cl ... No Module Public AccountCollection As Collection AccountCollection is the variable that I am checking for persistence. It is references by the vbMain module as Module Common which is a separate vb source file. Module Common .. Public aCL As New vbMain.QBAPIV3Cl() So what you are saying since MODULE common is a MODULE everything in it is Shared/Static including all of aCL????

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #10

                QuickBooksDev wrote:

                So what you are saying since MODULE common is a MODULE everything in it is Shared/Static including all of aCL????

                Yes, that's correct.

                Module Statement[^]:

                A module has the same lifetime as your program. Because its members are all Shared, they also have lifetimes equal to that of the program. ... All members of a module are implicitly Shared.


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                Q 1 Reply Last reply
                0
                • Richard DeemingR Richard Deeming

                  QuickBooksDev wrote:

                  So what you are saying since MODULE common is a MODULE everything in it is Shared/Static including all of aCL????

                  Yes, that's correct.

                  Module Statement[^]:

                  A module has the same lifetime as your program. Because its members are all Shared, they also have lifetimes equal to that of the program. ... All members of a module are implicitly Shared.


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  Q Offline
                  Q Offline
                  QuickBooksDev
                  wrote on last edited by
                  #11

                  So for a web app it last forever??? Is there a way of making a module non-Shared so I do not have to re-organize the program? Or what is the best way to have the module non-Shared?

                  Richard DeemingR 1 Reply Last reply
                  0
                  • Q QuickBooksDev

                    So for a web app it last forever??? Is there a way of making a module non-Shared so I do not have to re-organize the program? Or what is the best way to have the module non-Shared?

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #12

                    Yes, in a web application it will last until the AppPool recycles. There's no way to make a module non-shared. However, you might be able to get away with changing the field to a property, and adding code to retrieve the value from the current session if the code is running in an ASP.NET application. Something like this should work:

                    Imports System.Web
                    Imports System.Web.Hosting

                    Module Common
                    ' The key for the field in the session - this must be unique:
                    Private Const SessionKey As String = "Common::aCL"

                    ' Backing field used for non-web applications:
                    Private aCLNonWeb As vbMain.QBAPIV3Cl
                    
                    Public ReadOnly Property aCL() As vbMain.QBAPIV3Cl
                        Get
                            If Not HostingEnvironment.IsHosted Then
                                ' Not running in ASP.NET:
                                If aCLNonWeb Is Nothing Then
                                    Set aCLNonWeb = New vbMain.QBAPIV3Cl()
                                End If
                                
                                Return aCLNonWeb
                            End If
                            
                            Dim context As HttpContext = HttpContext.Current
                            If context Is Nothing Then
                                Throw New InvalidOperationException("No current request.")
                            End If
                            
                            Dim value As vbMain.QBAPIV3Cl = DirectCast(context.Session(SessionKey), vbMain.QBAPIV3Cl)
                            If value Is Nothing Then
                                value = New vbMain.QBAPIV3Cl()
                                context.Session.Add(SessionKey, value)
                            End If
                            
                            Return value
                        End Get
                    End Property
                    

                    End Module


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    Q 1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      Yes, in a web application it will last until the AppPool recycles. There's no way to make a module non-shared. However, you might be able to get away with changing the field to a property, and adding code to retrieve the value from the current session if the code is running in an ASP.NET application. Something like this should work:

                      Imports System.Web
                      Imports System.Web.Hosting

                      Module Common
                      ' The key for the field in the session - this must be unique:
                      Private Const SessionKey As String = "Common::aCL"

                      ' Backing field used for non-web applications:
                      Private aCLNonWeb As vbMain.QBAPIV3Cl
                      
                      Public ReadOnly Property aCL() As vbMain.QBAPIV3Cl
                          Get
                              If Not HostingEnvironment.IsHosted Then
                                  ' Not running in ASP.NET:
                                  If aCLNonWeb Is Nothing Then
                                      Set aCLNonWeb = New vbMain.QBAPIV3Cl()
                                  End If
                                  
                                  Return aCLNonWeb
                              End If
                              
                              Dim context As HttpContext = HttpContext.Current
                              If context Is Nothing Then
                                  Throw New InvalidOperationException("No current request.")
                              End If
                              
                              Dim value As vbMain.QBAPIV3Cl = DirectCast(context.Session(SessionKey), vbMain.QBAPIV3Cl)
                              If value Is Nothing Then
                                  value = New vbMain.QBAPIV3Cl()
                                  context.Session.Add(SessionKey, value)
                              End If
                              
                              Return value
                          End Get
                      End Property
                      

                      End Module


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      Q Offline
                      Q Offline
                      QuickBooksDev
                      wrote on last edited by
                      #13

                      Thanks will give it a try.

                      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