Dovberman
asked on
MembershipUser is not persistent.
Based on all the references,
Membership.GetUser(); should return the logged in user object when no parameters are included.
However this is not happening. There are no error messages.
Any ideas.
Membership.GetUser(); should return the logged in user object when no parameters are included.
However this is not happening. There are no error messages.
Any ideas.
protected void StockProLogin_Authenticate(object sender, AuthenticateEventArgs e)
{
if (Membership.ValidateUser(StockProLogin.UserName, StockProLogin.Password))
{
e.Authenticated = true;
MembershipUser currentUser = Membership.GetUser(StockProLogin.UserName);
// currentUser is not null Membership table is updated as expected.
MembershipUser newUser = Membership.GetUser();
//newUser is null.
web.config
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" />
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<membership defaultProvider="SQLProvider" userIsOnlineTimeWindow="15">
<providers>
<remove name="SqlMembershipProvider" />
<add name="SQLProvider" connectionStringName="MemberShipSQLConnectionString"
enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="true"
applicationName="StockPro"
requiresUniqueEmail="true" passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
passwordAttemptWindow="10" minRequiredNonalphanumericCharacters="0"
minRequiredPasswordLength="8"
type="System.Web.Security.SqlMembershipProvider,
System.Web,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
ASKER
Everything seems OK.
The user is authentication test returns true.
The user name is in the membership database.
MembershipUser currentUser = Membership.GetUser(StockPr oLogin.Use rName);
currentUser.Name returns "MaryAnn" as expected.
currentUser.Name returns currentUser object
the currentUser object is null outside of the Login validation section.
That's what I mean about the currentUser object not being persistent.
MembershipUser newUser = Membership.GetUser(); should not have returned null.
{
e.Authenticated = true;
MembershipUser currentUser = Membership.GetUser(StockPr oLogin.Use rName);
// currentUser is not null Membership table is updated as expected.
MembershipUser newUser = Membership.GetUser();
//newUser is null.
The user is authentication test returns true.
The user name is in the membership database.
MembershipUser currentUser = Membership.GetUser(StockPr
currentUser.Name returns "MaryAnn" as expected.
currentUser.Name returns currentUser object
the currentUser object is null outside of the Login validation section.
That's what I mean about the currentUser object not being persistent.
MembershipUser newUser = Membership.GetUser(); should not have returned null.
{
e.Authenticated = true;
MembershipUser currentUser = Membership.GetUser(StockPr
// currentUser is not null Membership table is updated as expected.
MembershipUser newUser = Membership.GetUser();
//newUser is null.
hey,
its strange.. are you sure that you have set the authentication mode in the web.config to "Forms" and it is not allowing anonymous access.
I think this should be because of some config settings in the web.config file can you check it.
Thanks and regards,
Venki
its strange.. are you sure that you have set the authentication mode in the web.config to "Forms" and it is not allowing anonymous access.
I think this should be because of some config settings in the web.config file can you check it.
Thanks and regards,
Venki
ASKER
Yes, See code included in original post.
web.config
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" />
</authentication>
<authorization>
<allow users="*"/>
</authorization>
The url you referred to has lead me to a possible solution that I am currently reviewing:
Reply 19 of http://forums.asp.net/p/939408/1119989.aspx
refers to:
http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx
web.config
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" />
</authentication>
<authorization>
<allow users="*"/>
</authorization>
The url you referred to has lead me to a possible solution that I am currently reviewing:
Reply 19 of http://forums.asp.net/p/939408/1119989.aspx
refers to:
http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx
ASKER
The reference resolved an inability to login. Users are able to login in my app.
I may need to contact Microsoft support.
I may need to contact Microsoft support.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1. Membership.GetUser() will only work for an authenticated user. Otherwise, it's going to return null. To verify you're dealing with an authenticated request call "User.Identity.IsAuthentic
2. If you're calling one of the Membership.GetUser() overloads which takes the username and it's returning null, then that user doesn't exist in the Membership datasource (or we've got a bug). One way to easily verify this is to try a Membership.CreateUser() with the same username. If this doesn't throw an error because of a duplicate user, then you know the user never existed in the first place.
3. Membership.GetUser() should have never worked for an anonymous user. No support was built into Membership for handling this case.
you can refer to the discussion in the following url
http://forums.asp.net/p/939408/1119989.aspx
Thanks and regards,
Venki