You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 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
I am trying to access the username of the currently logged on user in a web page. I have noticed the following 2 ways:
this.User.Identity.Name
HttpContext.Current.User.Identity.Name
What is the difference between these? Also I want to access the name of the currently logged on user from a Master page but neither of the above work. How can I do this?
Thanks.
HttpContext lets you get the info if you don't have a Page class reference (this). It's the same info either way. I prefer using the Page class reference if I have one.
I would expect HttpContext.Current.User to be valid in a Master page? Maybe I have to look into this...
Hmmm... HttpContext.Current.User seems to be working now. Too many beers I guess :-)
Actually, what I was trying to do was redirect automatically to the default admin page when an admin logged in using the Logged_In event of a login control: