Hi I use a custom MembershipProvider.
I want to know the current username during an application scenario, but when I try accessing HttpContext.Current.User.Identity.Name it always returns string.Empty.
if (Membership.ValidateUser(tbUsername.Text, tbPassword.Text))
{
FormsAuthentication.SetAuthCookie(tbUsername.Text, true);
bool x = User.Identity.IsAuthenticated; //true
string y = User.Identity.Name; //""
FormsAuthentication.RedirectFromLoginPage(tbUsername.Text, cbRememberMe.Checked);
}
Am I missing something?
As already suggested
FormsAuthentication.RedirectFromLoginPage()
method, sets the Authentication Cookie automatically.However in my case, i had nested web applications where i had cleared
<httpModules>
tag in child application (so that it does not inherit httpModules from its parent application) in theweb.config
file. Removing the unwanted parent httpModules made everything work again.its better to check this tag before complicating things :)