Thứ Năm, 16 tháng 4, 2009

Lấy User ID từ Data Access Layer

Iron Speed Designer maintains strict separation of the user interface layer from the Data Access Layer. For example, the currently logged in user is not available directly in the Data Access Layer. In some cases our users have asked to use this information even in the Data Access Layer.

You can access the user information from the session in the Data Access Layer. Use the fully specified session class to get access to this information.

System.Web.HttpContext.Current.Session

For example:

Dim sessionData As System.Collections.Hashtable

sessionData = CType(System.Web.HttpContext.Current.Session.Item( _

BaseClasses.Utils.SessionConst.LoginInfo), _

Hashtable)

Then you can use the following to get the variables:

CStr(sessionData(BaseClasses.Utils.SessionConst.UserId))

CStr(sessionData(BaseClasses.Utils.SessionConst.UserName))

CStr(sessionData(BaseClasses.Utils.SessionConst.UserTable))

CStr(sessionData(BaseClasses.Utils.SessionConst.UserRole))

For example, you can do something like the following:

Dim EmailContent As String = “The current user is: ” & _

CStr(sessionData(BaseClasses.Utils.SessionConst.UserName))

Source: http://www.ironspeed.com

Không có nhận xét nào: