Wednesday, July 25, 2012

use HttpContext.Current.User.Identity.Name in C#

In the name of fixing this, I experimented with the web forms code behind below:

using System;
namespace Tinkering
{
   public partial class _Default : System.Web.UI.Page
   {
      protected void Page_Load(object sender, EventArgs e)
      {
         System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
         MyControl.Text = "User: " + user.Identity.Name;
      }
   }
}

No comments:

Post a Comment