Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session vriables in another Tier

Status
Not open for further replies.

j0em0mma

Programmer
Jul 31, 2003
131
US
I have the following basic class in a Tier outside of the Web Layer that needs to access the session:

Code:
Imports System.Web.UI.WebControls




Namespace PageState.Sessions

    Public Class Sessions

        Private Sub NoUserObjectRedirect()

            If IsNothing(Session("CurUserObj")) = True Then
                Response.Redirect("./Login.aspx?TimedOut=TimedOut")
            End If

        End Sub

    End Class

End Namespace

what do I need to be able to access the current user's session in this layer?
 
I would suggest, instead of having to refer session variable directly, pass them as parameters of the function.

Something like below...

Private Function NoUserObjectRedirect(CurUserObj as boolean)
if CurUserObj = True then
....
End
End Function

When you call a function it will be like this...

NoUserObjectRedirect(Session("CurUserObj"))



I hope this helps...

Jignasu
 
Thanks Jignasu. I should have used a more complex example. Your suggestion is just fine for this scenario, however we're trying to make a mechanism that allows us to control the session outside of the individual page that is using it. Examples include using the Business Rules Layer to Login a user and set relevant session variables including userid, data and application security variables, etc...

Currently, we have a lot of repetitious code on every page that controls the session, which is the main issue. This is especially annoying when we're special casing a session variable in one script and then slightly changing that case in another script during the development process. These seem, to me, to be unneccessary "moving parts" in the application, and cause concurrency and legibility issues.
 
I am not sure if that could be done or not. But there are other ways you can have those information available to the web appliction. Since you are creating Business Rules Layer, you will have to that Bueiness Rule be used in Web Application. For example, when you access Authticate method of Business Rule, you could instead having to just return one value, you return collection of values, may be User collection, which might include Username, Name, address, etc. and save that in session. I am not usre if this scenario will help, but just something to think about.

Jignasu
 
Well, Good news...There is certainly a way...Here is what I tried and it works...You can indeed create new session variables from Business Layer...

Here is one of the function in my Business class...

Public Function Test(ByRef context As HttpContext)
context.Session("Test") = "Test"
End Function

Here is what I have in my Page_Load..

Dim test As New ClassLibrary1.Class1
test.Test(context)

Response.Write(Session("Test"))

And I see "Test" on my web page.

I hope this will help...and I hope this is what you are looking for...

Jignasu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top