Hi Frds,
I am very new to Sessions
My application is Financial based....It is developed in ASP.net 3.5 using vb.net coding
This application in stateless nature...I want to updated this application with sql server mode using sessions
This application will inherit all the pages from Base page in which the credentials including company name and locarion name
comes from login screen
I want to maintain sessions fro this variables in order to work in mutilple user environment
Any help is appreciated..
Thanks,
Kishore.j
Loading
kishore JangamPosted Jul 30, 2009, 3:18 AM
I have passed the session variables to all the pages in stead of passing to base page....
It is working ...but i think it will be proper solution
i am sendinng the code of login page and web config page
Login page
Imports System.Data.Linq
Imports DataAccessLayer
Imports BusinessLogicLayer
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.SessionState.HttpSessionState
Imports System.Web.HttpCookieCollection
Partial Class Login
Inherits BasePage
Public Shared sessionId As Object
Private _loginMapperObject As LoginMapper
Protected Overrides Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
_loginMapperObject = New LoginMapper(DataContext)
txtPassword.Attributes.Add("value", txtPassword.Text)
'companycode = String.Empty
'locationcode = String.Empty
'_userId = String.Empty
'role = String.Empty
'_username = String.Empty
If Not Page.IsPostBack Then
ddlCompanyName.DataSource = _loginMapperObject.companyname()
ddlCompanyName.DataTextField = "Comp_Desc"
ddlCompanyName.DataValueField = "Comp_Code"
ddlCompanyName.DataBind()
ddlCompanyName.Items.Insert(0, "Select")
txtUserName.Focus()
End If
ClearUserMessages()
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If String.IsNullOrEmpty(txtUserName.Text) Then
errorDiv.InnerHtml = String.Format("Please Enter Username")
errorDiv.Visible = True
Return
End If
If String.IsNullOrEmpty(txtPassword.Text) Then
errorDiv.InnerHtml = String.Format("Please Enter Password")
errorDiv.Visible = True
Return
End If
'Try
' _loginMapperObject.User_Validations(txtUserName.Text, txtPassword.Text, ddlCompanyName.SelectedValue, ddlCompanyLocation.SelectedValue)
' 'Session("UserName") = (txtUserName.Text).Trim()
' 'Session("Password") = (txtPassword.Text).Trim()
' 'Dim username = _loginMapperObject.getEmployeeName(txtUserName.Text)
' Dim basepage As BasePage = Nothing
' basepage._userId = txtUserName.Text.Trim()
' 'basepage._username = username.first_name + " " + username.middle_name + " " + username.last_name
' If ddlCompanyName.SelectedItem.Text = "Select" Then
' errorDiv.InnerHtml = String.Format("Select Company name")
' errorDiv.Visible = True
' Return
' End If
' basepage.companyname = ddlCompanyName.SelectedItem.Text
' basepage.companylocation = ddlCompanyLocation.SelectedItem.Text
' basepage.companycode = ddlCompanyName.SelectedValue
' basepage.locationcode = ddlCompanyLocation.SelectedValue
' If String.IsNullOrEmpty(basepage.companyname) Then
' errorDiv.InnerHtml = String.Format("Select Company name")
' errorDiv.Visible = True
' Return
' End If
' Dim role = _loginMapperObject.getUserRole(ddlCompanyName.SelectedValue, ddlCompanyLocation.SelectedValue, txtUserName.Text)
' basepage.role = role.rolename
' Dim _url = "HomePage.aspx"
' Response.Redirect(_url)
'Catch ex As ArgumentException
' errorDiv.InnerHtml = String.Format(ex.Message)
' errorDiv.Visible = True
'End Try
'Login_sessions()
'If String.IsNullOrEmpty(Session("UserName").ToString) Then
' errorDiv.InnerHtml = String.Format("Please Enter Username")
' errorDiv.Visible = True
' Return
'End If
'If String.IsNullOrEmpty(txtPassword.Text) Then
' errorDiv.InnerHtml = String.Format("Please Enter Password")
' errorDiv.Visible = True
' Return
'End If
Try
_loginMapperObject.User_Validations(txtUserName.Text, txtPassword.Text, ddlCompanyName.SelectedValue, ddlCompanyLocation.SelectedValue)
Dim _Login_Sessions As New Login_Sessions(txtUserName.Text, ddlCompanyName.SelectedValue, ddlCompanyLocation.SelectedValue _
, ddlCompanyName.SelectedItem.Text, ddlCompanyLocation.SelectedItem.Text)
Session("Login_Sessions") = _Login_Sessions
Dim _Login_Sessions1 As Login_Sessions = DirectCast(Session("Login_Sessions"), Login_Sessions)
Dim basepage As BasePage = Nothing
basepage._userId = _Login_Sessions1.U_id.ToString()
'basepage._username = username.first_name + " " + username.middle_name + " " + username.last_name
If (_Login_Sessions1.Cmpy_Name.ToString()) = "Select" Then
errorDiv.InnerHtml = String.Format("Select Company name")
errorDiv.Visible = True
Return
End If
basepage.companyname = _Login_Sessions1.Cmpy_Name.ToString()
basepage.companylocation = _Login_Sessions1.Loc_Name.ToString()
basepage.companycode = _Login_Sessions1.cmpy_code.ToString()
basepage.locationcode = _Login_Sessions1.Loc_code.ToString()
If String.IsNullOrEmpty(basepage.companyname) Then
errorDiv.InnerHtml = String.Format("Select Company name")
errorDiv.Visible = True
Return
End If
Dim role = _loginMapperObject.getUserRole(_Login_Sessions1.cmpy_code.ToString(), _Login_Sessions1.Loc_code.ToString(), _
_Login_Sessions1.U_id.ToString())
basepage.role = role.rolename
Dim _url = "HomePage.aspx"
Response.Redirect(_url)
Catch ex As ArgumentException
errorDiv.InnerHtml = String.Format(ex.Message)
errorDiv.Visible = True
End Try
End Sub
Protected Sub ddlCompanyName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCompanyName.SelectedIndexChanged
ddlCompanyLocation.DataSource = _loginMapperObject.companylocation(ddlCompanyName.SelectedValue)
ddlCompanyLocation.DataTextField = "Loc_Desc"
ddlCompanyLocation.DataValueField = "Loc_Code"
ddlCompanyLocation.DataBind()
btnLogin.Focus()
End Sub
Public Sub ClearUserMessages()
errorDiv.EnableViewState = False
errorDiv.Visible = False
End Sub
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
txtUserName.Text = String.Empty
txtPassword.Attributes.Add("value", String.Empty)
ddlCompanyName.SelectedIndex = 0
If ddlCompanyName.SelectedValue = "Select" Then
ddlCompanyLocation.Items.Clear()
End If
ClearUserMessages()
End Sub
'Protected Sub Login_sessions()
' Try
' 'Session("UserName") = txtUserName.Text
' 'Session("CompanyName") = ddlCompanyName.SelectedValue
' 'Session("CompanyLocation") = ddlCompanyLocation.SelectedValue
' 'Session("CompanyNamedesc") = ddlCompanyName.SelectedItem.Text
' 'Session("CompanyLocationdesc") = ddlCompanyLocation.SelectedItem.Text
' 'Session("Login_Time") = System.DateTime.Now
' 'Dim obj As New HttpCookieCollection
' 'obj.Set(Session("Username"))
' 'obj.Set(Session("CompanyName"))
' 'obj.Set(Session("CompanyLocation"))
' 'obj.Set(Session("CompanyNamedesc"))
' 'obj.Set(Session("CompanyLocationdesc"))
' 'TheSessionId()
' 'Session.Add("session", Session.SessionID)
' 'If Not Session.SessionID = "" Then
' ' Session.IsNewSession.ToString()
' 'Else
' ' Session.SessionID.StartsWith("SessionId")
' 'End If
' 'MsgBox("Success" + Session.SessionID)
' Catch ex As Exception
' ShowError(ex.Message)
' End Try
'End Sub
'Public Shared Function TheSessionId() As String
' Dim ss As HttpSessionState = HttpContext.Current.Session
' HttpContext.Current.Session("SessionId") = ss.SessionID
' HttpContext.Current.Response.Write(ss.SessionID)
' Return (sessionId)
'End Function
End Class
Public Class Login_Sessions
Public Sub New()
End Sub
Public Sub New(ByVal User_Id As String, ByVal companycode As String, ByVal Locationcode As String, ByVal companyName As String, ByVal locationname As String)
Me.U_id = User_Id
Me.cmpy_code = companycode
Me.Loc_code = Locationcode
Me.Cmpy_Name = companyName
Me.locationname = locationname
End Sub
Private User_Id As String
Private companycode As String
Private Locationcode As String
Private companyName As String
Private locationname As String
Public Property U_id() As String
Get
Return User_Id
End Get
Set(ByVal value As String)
User_Id = value
End Set
End Property
Public Property cmpy_code() As String
Get
Return companycode
End Get
Set(ByVal value As String)
companycode = value
End Set
End Property
Public Property Loc_code() As String
Get
Return Locationcode
End Get
Set(ByVal value As String)
Locationcode = value
End Set
End Property
Public Property Cmpy_Name() As String
Get
Return companyName
End Get
Set(ByVal value As String)
companyName = value
End Set
End Property
Public Property Loc_Name() As String
Get
Return locationname
End Get
Set(ByVal value As String)
locationname = value
End Set
End Property
End Class
web config file
Niradhip ChakrabortyPosted Jul 30, 2009, 3:04 AM
kishore JangamPosted Jul 30, 2009, 2:50 AM
Thanks for replying.....
If u have any other soultion please forward to me...
Thanks ,
Kishore.J
Niradhip ChakrabortyPosted Jul 30, 2009, 1:17 AM
cookieless sessions causes the ASP.NET runtime to munge a session ID into
the URL, in the format http://yourapplicationpath/(Session.SessionID)/...
which saves numerous headaches when it comes to storing state across page
requests and sessions.
CheckOut the Session State settings in Web.config.
Obviously if you are checking using same URL in same system then session value will override as soon as second user will login.
If multiple user login from different system using same URL it will not happend I guess.
kishore JangamPosted Jul 30, 2009, 12:44 AM
kishore JangamPosted Jul 30, 2009, 12:42 AM
I Tried using the cookieless nature, but it is not working
Actual Problem is ,when second User login with the different credentails and different company ..the first user loses the credentails and getting the second user credentails
Thanks,
Kishore J
Niradhip ChakrabortyPosted Jul 29, 2009, 3:31 AM
Storage location
InProc - session kept as live objects in web server (aspnet_wp.exe). Use "cookieless" configuration in web.config to "munge" the sessionId onto the URL (solves cookie/domain/path RFC problems too!)
StateServer - session serialized and stored in memory in a separate process (aspnet_state.exe). State Server can run on another machine
SQLServer - session serialized and stored in SQL server
Performance
InProc - Fastest, but the more session data, the more memory is consumed on the web server, and that can affect performance.
StateServer - When storing data of basic types (e.g. string, integer, etc), in one test environment it's 15% slower than InProc. However, the cost of serialization/deserialization can affect performance if you're storing lots
of objects. You have to do performance testing for your own scenario.
SQLServer - When storing data of basic types (e.g. string, integer, etc), in one test environment it's 25% slower than InProc. Same warning about serialization as in StateServer.
You can hold the details in session in login page and use it in other pages of your application.
If you have any other doubts please let me know.