Example Using Session_Start in Global.asax

In the Global.asax.cs of your ASP.NET site:

Using the current windows authenticated username pass this to our webservice which will pass us back info about this user which we can use in our system

 /// <summary>
        /// Handles the Start event of the Session control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Session_Start(object sender, EventArgs e)
        {
            Session["EhapUser"] = UserServiceManager.GetEHAPUser(HttpContext.Current.User.Identity.Name.Remove(0, 5));
        }

Then in your MasterPage code behind:

Reference the object that is now in session

       protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                EHAPUser user = (EHAPUser)Session["EhapUser"];
                if(user == null)
                    lblLogon.Text = HttpContext.Current.User.Identity.Name;
                else
                    lblLogon.Text = user.FullName;
                lblApplicationVersion.Text = ConfigurationManager.AppSettings["applicationVersion"];
            }
            ErrorMessage = null;
        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s