Using VS2013 Update 1 I created a new WebForms project. This project uses the "new" Identity membership provider. I did not want to use that so I reverted back to the Membership provider (For more detail see Webforms HttpContext.Current.User.Identity.IsAuthenticated always true)
I must still have something still wrong as once the user has authenticated when I inspect:
System.Web.HttpContext.Current.User.Identity.Name
I am getting:
"/"
as the result instead of the name the user entered when they logged in via:
Membership.ValidateUser(txtUserName.Text, txtPassword.Text) ie. why am I not getting the value of txtUserName.Text instead of /
I have verified that the SQL being exectuted when
HttpContext.Current.User.Identity.Name
is being accessed is returning the expected values via the following SQL:
SELECT
[Limit1].[C1] AS [C1],
[Limit1].[UserName] AS [UserName],
[Limit1].[UserId] AS [UserId],
[Limit1].[Email] AS [Email],
[Limit1].[PasswordQuestion] AS [PasswordQuestion],
[Limit1].[Comment] AS [Comment],
[Limit1].[IsApproved] AS [IsApproved],
[Limit1].[IsLockedOut] AS [IsLockedOut],
[Limit1].[CreateDate] AS [CreateDate],
[Limit1].[LastLoginDate] AS [LastLoginDate],
[Limit1].[LastActivityDate] AS [LastActivityDate],
[Limit1].[LastPasswordChangedDate] AS [LastPasswordChangedDate],
[Limit1].[LastLockoutDate] AS [LastLockoutDate]
FROM ( SELECT TOP (1)
[Extent1].[UserId] AS [UserId],
[Extent1].[UserName] AS [UserName],
[Extent1].[LastActivityDate] AS [LastActivityDate],
[Extent3].[Email] AS [Email],
[Extent3].[PasswordQuestion] AS [PasswordQuestion],
[Extent3].[IsApproved] AS [IsApproved],
[Extent3].[IsLockedOut] AS [IsLockedOut],
[Extent3].[CreateDate] AS [CreateDate],
[Extent3].[LastLoginDate] AS [LastLoginDate],
[Extent3].[LastPasswordChangedDate] AS [LastPasswordChangedDate],
[Extent3].[LastLockoutDate] AS [LastLockoutDate],
[Extent3].[Comment] AS [Comment],
1 AS [C1]
FROM [dbo].[Users] AS [Extent1]
INNER JOIN [dbo].[Applications] AS [Extent2] ON [Extent1].[ApplicationId] = [Extent2].[ApplicationId]
INNER JOIN [dbo].[Memberships] AS [Extent3] ON [Extent1].[UserId] = [Extent3].[UserId]
) AS [Limit1]
here is my web.config:
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="MyApp2" />
</providers>
</membership>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="MyApp2" />
</providers>
</profile>
<roleManager defaultProvider="DefaultRoleProvider" enabled="true">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="MyApp2" />
</providers>
</roleManager>
so the issue "must be" that I have the Identity membership provider referenced in some way somewhere. Can anyone help me out here as I am really stuck.
I guess a related question is, is there a HOWTO on how to revert a project from Identity to the previous Membership system?
EDIT
After thinking it was all working after changing the applicationName to "MyApp" when I went back to play with the app again I am back to the old "bad" behavior where I get "/" for the user name. So I changed the database to MyApp2 as well as the web.config and still no difference.
I now also include a screenshot of the tables from the database in case this helps with anything. I really need to figure this out so would appreciate any insights. Am also happy to provide other diagnostics as needed.
Well it is always the simple solution isn't it?
As it turns out I had not placed my ASPX code for my login page within an aspx:login. This meant that the cookie was not getting set correctly as all I was doing was Membership.RedirectFromLogin().
So once I put things into an aspx:login all was well. Hope this helps someone else in the future.