This example demonstrates how to get the current logged in windows user by using an ASP.NET Web Form named “MyWebForm.aspx” and a code behind page named “MyWebForm.aspx.cs”. The Web Form has a single text box control named “TextBox1”. “this” represents System.Web.UI.Page, which has a public instance variable named “Request” of type System.Web.HttpRequest.
using System;

namespace MyNamespace
{
public partial class MyWebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = this.Request.LogonUserIdentity.Name;
}
}
}

Advertisements