Esempio di classe CurrentUser.cs in c#
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// <summary> /// Summary description for CurrentUser /// </summary> public class CurrentUser { private UsersBLL _UsersBLL; private DS.UserRow _User = null; protected UsersBLL UsersBLL { get { if (_UsersBLL == null) { _UsersBLL = new UsersBLL(); } return _UsersBLL; } } public CurrentUser() { } private System.Web.Profile.ProfileBase Profile { get { return HttpContext.Current.Profile; } } private System.Web.SessionState.HttpSessionState Session { get { return HttpContext.Current.Session; } } public int UserID { get { int intUserID = 0; if (Session["UserID"] != null) { return Convert.ToInt32(Session["UserID"]); } if (User != null) { intUserID = User.ID; Session["UserID"] = intUserID; } return intUserID; } set { Session["UserID"] = value; } } /* If we assign to UserID, we know they are logged on * this is worth doing becuase, although FormsAuthentication.SetAuthCookie * logs people on for subsequent requests (Profile.IsAnonymous = false), it * doesnt work on the current request as the profile object has already been set up.*/ public bool IsLoggedOn { get { if (HttpContext.Current.Items["IsLoggedOn"] != null) { return Convert.ToBoolean(HttpContext.Current.Items["IsLoggedOn"]); } return !Profile.IsAnonymous; } set { HttpContext.Current.Items["IsLoggedOn"] = value; } } public DS.UserRow User { get { if (_User == null) { if (Profile.IsAnonymous) { _User = null; } else { DS.UserDataTable UserDataTable = UsersBLL. GetDataByUserName(Profile.UserName); if (UserDataTable.Rows.Count > 0) { _User = (DS.UserRow)UserDataTable.Rows[0]; } else { _User = null; } } } return _User; } set { _User = value; } } }
City: All World