jeffhodgeson
asked on
Class Module using Session State Access now also needs to be used by windows application
I have a class module called by a web application that will set its connection string based on a session state variable set by the web app when a user logs on (actually multiple class modules). The connection string is set when the class is created. I now need to use the same class module in a windows application.
Best solution I've come up with so far is to test for the existance of the System.Web.HttpContext.Cur rent object at initialization time of the class module. If it exists then get the connection string from the session state variable, else read the connection string from the app.config for the windows app creating the class.
Does anyone have any other ideas? I suppose I could pass the connection string when creating the class modules.
Best solution I've come up with so far is to test for the existance of the System.Web.HttpContext.Cur
Does anyone have any other ideas? I suppose I could pass the connection string when creating the class modules.
ASKER
Reading from whichever config file does work fine except that there are 2 possible connection strings in the config file and the one to select is determined by the web app which creates these class modules. This web app will set a session state variable for use by the class modules now. The class modules do not have the needed information to determine which of the 2 connection strings to use.
For now I'm I'm checking for the existance of the System.Web.HttpContext.Cur rent object. If it exists I use it to get the connection string from the session state variable as the module is being consumed by the web app. If the object does not exists the object is being consumed by the windows app and it just pulls in the primary connection string from the app.config file.
If System.Web.HttpContext.Cur rent Is Nothing Then
connString = ConfigurationManager.Conne ctionStrin gs("ConnSt ring1").Co nnectionSt ring
Else
Dim currContext As HttpContext = System.Web.HttpContext.Cur rent
connString = currContext.Session("ConnS tring").To String
End If
For now I'm I'm checking for the existance of the System.Web.HttpContext.Cur
If System.Web.HttpContext.Cur
connString = ConfigurationManager.Conne
Else
Dim currContext As HttpContext = System.Web.HttpContext.Cur
connString = currContext.Session("ConnS
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Alternativeley have the client code which creates the class pass in the connection string into the constructor that way the class is indifferent to the client code which is better architecture.