Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
 
    
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 7-Nov-12 4:11am
Edited 7-Nov-12 4:15am
jim lahey24.9K
v2
Comments
Mathlab at 7-Nov-12 9:22am
   
Are you using tokens?
SandhyaPillai at 8-Nov-12 8:34am
   
no

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
SandhyaPillai at 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)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 PIEBALDconsult 160
4 CPallini 155
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100