views:

301

answers:

3

i see i can call Request.IsAuthenticated but how do i get the login name from asp.net membership provider once i am logged in?

A: 

try

Request.LogonUserIdentity
TheVillageIdiot
A: 
Page.User.Identity.Name
awe
+2  A: 

There's a number of mechanisms to get the currently logged on user's name, for example, you can get to it via the context of the current web page like so:

Page.User.Identity.Name

However, usually the best way to get the current user's name is via the context of the current Http request like so:

HttpContext.Current.User.Identity.Name

Ultimately, you're calling down into the same "User" object, and accessing the same System.Security.Principal.IIdentity object instance in either case, but using the HttpContext allows this code to be used not only in web pages but also ASP.NET user controls and POCO classes etc.

CraigTP