Solved

MembershipUser is not persistent.

Posted on 2009-03-29
6
624 Views
Last Modified: 2012-05-06
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.


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>

Open in new window

0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 21

Expert Comment

by:tovvenki
ID: 24026457
Hi,
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.IsAuthenticated" on the page.  If you've got an authenticated request, but Membership.GetUser() is still returning null, then that means the username associated with the authenticated user can't be found in the Membership datasource.  Verify the username of the authenticated user with "User.Identity.Name".

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
0
 

Author Comment

by:Dovberman
ID: 24027668
Everything seems OK.
The user is authentication test returns true.
The user name is in the membership database.

MembershipUser currentUser = Membership.GetUser(StockProLogin.UserName);
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(StockProLogin.UserName);
            // currentUser is not null Membership table is updated as expected.
            MembershipUser newUser = Membership.GetUser();
           //newUser is null.
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 24027763
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dovberman
ID: 24027966
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 

0
 

Author Comment

by:Dovberman
ID: 24028302
The reference resolved an inability to login. Users are able to login in my app.

I may need to contact Microsoft support.
0
 

Accepted Solution

by:
Dovberman earned 0 total points
ID: 24044237
Called Microsoft support. The SetAuthCookie method resolved this issue.
 protected void StockProLogin_Authenticate(object sender, AuthenticateEventArgs e)
    {
   
        if (Membership.ValidateUser(StockProLogin.UserName, StockProLogin.Password))
        {
            FormsAuthentication.SetAuthCookie(StockProLogin.UserName, false);
            Response.Redirect("~/MasterPages/Default.aspx");
        }
        else
        {
            Response.Redirect("~/FindPriceExceptions.aspx");
        }

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question