But, how can i make sure my asp.net application (masterpage gets it forst to use it in my logivview)?
Forgive me if I am still not clear about what is your purpose. Could you please provide more information about your code? Could you explain it more clearly?
That will help us to continue.
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
From the code behind on Page_Load use the FindControl method of your LoginView to snag the label and set the name to whatever you want.
var nameLabel = (Label)HeadLoginView.FindControl("NameLabel");
if (nameLabel != null)
nameLabel.Text = CurrentUser.FirstName;
In my case CurrentUser is a Property which returns a linq to sql type from my users table with more usefull information. I use the Page User.Identity.Name to select the relevent record. If you're doing this from a master page HttpContext.Current.User.Identity.Name
will give you the same.
Marked as answer by jagjot on Apr 16, 2013 10:15 AM
jagjot
Contributor
2655 Points
1245 Posts
Change LoginView domain\username to username
Apr 23, 2012 01:42 PM|LINK
Folks,
Curently my application is displaying domain\username. How can i change it to username only?
thanks in advance..
M.Sc, MIEEE, MCP, CCNA
bakra
Member
342 Points
59 Posts
Re: Change LoginView domain\username to username
Apr 23, 2012 02:02 PM|LINK
You can try something like the following:
string userName = HttpContext.Current.User.Identity.Name.ToString();
int stop = userName.IndexOf("\\");
userName = userName.Substring(stop + 1, userName.Length - stop - 1); //username without the domain part
Please "Mark as Answer" if this helped you
jagjot
Contributor
2655 Points
1245 Posts
Re: Change LoginView domain\username to username
Apr 23, 2012 02:36 PM|LINK
Dosent work.
It's to do with arthitecture of role management...
M.Sc, MIEEE, MCP, CCNA
bakra
Member
342 Points
59 Posts
Re: Change LoginView domain\username to username
Apr 23, 2012 03:12 PM|LINK
That's really odd because it worked for me. See links below for possible solution:
http://stackoverflow.com/questions/349520/net-built-in-helper-to-parse-domain-username-in-user-identity-name
http://stackoverflow.com/questions/330320/how-to-get-username-without-domain
http://stackoverflow.com/questions/3494709/sharepoint-retrieving-username-without-domain-or-programmtically-removing-domain
Please "Mark as Answer" if this helped you
jagjot
Contributor
2655 Points
1245 Posts
Re: Change LoginView domain\username to username
Apr 24, 2012 02:56 PM|LINK
Hi,
http://stackoverflow.com/questions/330320/how-to-get-username-without-domain worked perfectly for me.
But, how can i make sure my asp.net application (masterpage gets it forst to use it in my logivview)?
thanks in advance...
M.Sc, MIEEE, MCP, CCNA
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: Change LoginView domain\username to username
May 02, 2012 09:45 AM|LINK
Hi jagjot,
Sorry for delay reply!
Forgive me if I am still not clear about what is your purpose. Could you please provide more information about your code? Could you explain it more clearly?
That will help us to continue.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
jagjot
Contributor
2655 Points
1245 Posts
Re: Change LoginView domain\username to username
May 14, 2012 10:41 AM|LINK
My Application is displaying domain\username in loginview (welcom box). Want to display only username.
Thanks
M.Sc, MIEEE, MCP, CCNA
Ravi Kumar K...
Member
735 Points
159 Posts
Re: Change LoginView domain\username to username
May 14, 2012 10:43 AM|LINK
Just use the string and cut it to username like
string username=oldvalue.substring(oldvalue.lastIndexOf("\\"),oldvalue.Length)
jagjot
Contributor
2655 Points
1245 Posts
Re: Change LoginView domain\username to username
May 14, 2012 10:58 AM|LINK
Problem is that value is automatically added into loginview control. how can i set my own value into role management class?
M.Sc, MIEEE, MCP, CCNA
Armadous
Member
12 Points
1 Post
Re: Change LoginView domain\username to username
Jun 25, 2012 05:13 PM|LINK
Here's what I do.
Replace the LoginName control from your LoggedInTemplate section with a regular ol label.
<LoggedInTemplate> Welcome <span class="bold"><asp:Label ID="NameLabel" runat="server"></asp:Label></span>! [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ] </LoggedInTemplate>From the code behind on Page_Load use the FindControl method of your LoginView to snag the label and set the name to whatever you want.
var nameLabel = (Label)HeadLoginView.FindControl("NameLabel"); if (nameLabel != null) nameLabel.Text = CurrentUser.FirstName;In my case CurrentUser is a Property which returns a linq to sql type from my users table with more usefull information. I use the Page User.Identity.Name to select the relevent record. If you're doing this from a master page HttpContext.Current.User.Identity.Name will give you the same.