Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
We have a web application with access to Business logic and data access in separate projects.

The way it is designed, key values is never passed to data access layer or business logic. Instead business layer has a class which contains public read only property through which DAL layer access the values.

Business logic layer is in a different project. Web project gets the reference.
Business logic layer has this class : Public NotInheritable Class clsUserProfile
Which has this property:

VB
Public ReadOnly Property AgencyCode() As Integer

    Get
        If (HttpContext.Current.Session(_AgencyCodeKey) Is Nothing) Then
            Return 0
        Else
            Return HttpContext.Current.Session(_AgencyCodeKey)
        End If
    End Get

End Property


Will the data will be overwritten when multiple users login.
Many people say that it is not advisable, but cannot find any provable reason as to why it is not recommended?

If anybody can give clear reasons that would be great.

Thanks,
sandy
Posted
Updated 7-Nov-12 3:15am
v2
Comments
[no name] 7-Nov-12 9:22am    
Are you using tokens?
SandhyaPillai 8-Nov-12 8:34am    
no

1 solution

The data won't be overwritten when multiple users log in. It's a session variable and as the name suggests, it's per-session. Simply put, each user would have their own copy of the variable.

Personally I wouldn't do it this way because you've tightly coupled your business logic to a web-only implementation. If you try to access anything in the HttpContext from anything other than a web or certain WCF apps, you'll get an exception.

A compromise would be to check if HttpContext.Current is null before doing anything with it, although even this can yield false positives if you try to access HttpContext too early on the request pipeline.
 
Share this answer
 
Comments
SandhyaPillai 7-Nov-12 9:51am    
I do not like the way it is and I try telling that httpcontext shouldn't be used outside the web app. but opposition is asking for a proof. even if you are aware of any msdn web site please let me know. by then way......

Code is modified so that it can be accessed by both windows & web app
Public ReadOnly Property AgencyCode() As Integer

Get
If clsAppInfo.IsWebApplication Then
If (HttpContext.Current.Session(_AgencyCodeKey) Is Nothing) Then
Return 0
Else
Return HttpContext.Current.Session(_AgencyCodeKey)
End If
Else
Return AgencyCodeWIN
End If
End Get

End Property

/****** For windows Agency Code is declared as shared
Public Shared Property AgencyCodeWIN() As Integer
Get
Return _AgencyCodeWIN
End Get
Set(ByVal value As Integer)
_AgencyCodeWIN = value
End Set

End Property


/************
To determine whether it is a web app or not .......

Public Shared ReadOnly Property IsWebApplication() As Boolean
Get
If AppCodeWIN IsNot String.Empty Then
'Desk top App is required to pass AppInfo
Return False
Else
'Web App is default
Return True
End If
End Get
End Property

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900