I have a SP2010 site with FBA using Active directory membership provider. I am building an application page (under /_layouts) that only authenticated users can access. In this page's code behind, I am trying to get the current user login name. For some reason, I always have SPContext.Current.Web.CurrentUser as NULL. Though the authentication seems to be working correctly as the username is shown correctly on the page (on this menu that has "sign as different user" and "sign out").
Interestingly, HttpContext.Current.User shows the correct username.
Why is the SharePoint always returning NULL for CurrentUser? How can I get the current user from the SP context?