troubleshooting Question 2.0 c# get current user's identity

Avatar of fwsteal
fwsteal asked on
5 Comments1 Solution344 ViewsLast Modified:
How should I get the current user's identity via the class file below?

welcome.ascx control contents:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Net;
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;
using System.Security.Principal;
using System.IO;

public partial class welcome : System.Web.UI.UserControl
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            // get current user's identity
            WindowsIdentity wi = WindowsIdentity.GetCurrent();
            string accountName = wi.Name.ToString();
            string[] values = accountName.Split(@"\".ToCharArray()); //split it
            string MyDomain = values[0]; //domain
            string MyUserID = values[1]; //userid

            //get user's FullName
            LabelFullName.Text = " " + UserInfo.GetUserFullName(MyUserID).FullName.ToString();
app_code/bll/clsUserInfo.cs contents:

using System;
using System.Data;
using System.Data.Common;
using System.Security.Principal;
using System.DirectoryServices;

public struct UserFullName
    public string FullName;

public static class UserInfo
      static UserInfo()


    //get user full name
    public static UserFullName GetUserFullName(string UserID)
        // get a configured DbCommand object
        DbCommand comm = GenericDataAccess.CreateCommand();
        // set the stored procedure name
        comm.CommandText = "usp_GetUserFullName";
        // create a new parameter
        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@email_id";
        param.Value = UserID;
        param.DbType = DbType.String; //varchar;
        // execute the stored procedure
        DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
        // wrap retrieved data into a UserDetails object
        UserFullName details = new UserFullName();
        if (table.Rows.Count > 0)
            details.FullName = table.Rows[0]["FullName"].ToString();
            details.FullName = "N/A";
        // return user details
        return details;

// how to get current user's identity?


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros