Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 24th, 2007, 06:16 AM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default LoginName Control

Page 760 of Special Edition Professional ASP.NET 2.0: for me the LoginName returns <domain>/<UserName>. Is there a way to get rid of the <domain> and just return the UserName?

 
Old August 25th, 2007, 08:53 AM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, this is all I can come up with on a page load:

Dim username As String
username = Request.LogonUserIdentity.Name.Remove(0, 9)
   'where the domain + the "\" are nine characters

LoginName1.FormatString = username

I don't know enough about strings to be able to remove the "\" and all the characters before it to make the code universal. BTW..the LoginName is used with Windows authentication.

 
Old August 25th, 2007, 10:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Steve,

You can use Split to get the part after the \ like this:

userName = Request.LogonUserIdentity.Name.Split("\")(1)

Split creates an array based on the \ and then returns the second element that contains the user's name.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 25th, 2007, 11:16 AM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar!
Works like a charm. I spent some time reading up on strings and saw the split, but had no idea how to implement it. Thanks again, Steve






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to store user name from LoginName control melania BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 November 3rd, 2008 02:28 PM
How to put a button control in a GridView control ryan.webb ASP.NET 2.0 Basics 2 December 28th, 2007 05:26 AM
Can't move focus to control <control scptech Access VBA 8 October 26th, 2007 12:16 PM
LoginName hcanales ASP.NET 1.x and 2.0 Application Design 1 July 26th, 2006 03:16 PM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.