Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

How to display login user name without web part on all pages.

  Asked By: Ryan    Date: Aug 24    Category: Sharepoint    Views: 2177

How to display login user name without web part on all pages.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Noah Carr     Answered On: Aug 24

By using following code ur problem is solved

But I cant get you regarding “all pages  means “at what level do you want to display  username
in all subsites
or all sites
or Portal level

U have to write this code in common header


//This returns domain\username
protected string CurrentUserName()
{
SPWeb web  = SPControl.GetContextWeb(Context);
return SPControl.GetContextWeb(Context).CurrentUser.LoginName;
}


//This will return the user's Friendly name ie. " vamsi "
protected string CurrentName()
{
SPWeb web = SPControl.GetContextWeb(Context);
return SPControl.GetContextWeb(Context).CurrentUser.Name;
}


//This parses out the just the username
protected string CurrentUserName()
{
string name = SPControl.GetContextWeb(Context).CurrentUser.LoginName;
string[] temp = name.Split('\\');
return temp[1];
}


//Another way to get the current user  name from just the Context
protected string CurrentUserNameB()
{
string name = Context.User.Identity.Name;
string[] temp = name.Split('\\');
return temp[1];
}


//Another way to get current user name
//Here, you would pass SPWeb web = SPControl.GetContextWeb(Context).
//Maybe you already have the SPWeb object lying around from some other calculation.
protected string CurrentUserName(SPWeb web)
{
string name = web.CurrentUser.LoginName;
string[] temp = name.Split('\\');
return temp[1];
}

//This also returns domain\username from just the Context
protected string CurrentUserNameB()
{
return Context.User.Identity.Name;
}

 
Answer #2    Answered By: Skyler Poole     Answered On: Aug 24

How to display  login user  name without web  part on all pages.

The problem is that i want to show login  user name in all pages  of portal & sites.

 




Tagged: