Solved

Custom ExtendedMemebershipProvider MembershipUser GetUser Object Instance Error?

Posted on 2013-11-01
3
416 Views
Last Modified: 2013-11-08
I keep getting the error: "Object reference not set to an instance of an object." on the italic code below. It code seems straight forward, Intellisense is happy and it compiles in VS2012. The only problem is that it won't run in a browser without error. I guess the MemberShipUser doesn't want to play nice. Help!

Note: This code runs after clicking the Login 'Submit' button.

Q. How Do I get this method to return a MembershipUser?

public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            var user = (from u in entities.Users.ToList() where u.UserName == username select u).FirstOrDefault();

            var member = new MembershipUser(this.Name, user.UserName, user.UserID, user.Email, null, null, true, (bool)user.IsLockedOut, System.DateTime.Now, System.DateTime.Now, System.DateTime.Now, System.DateTime.Now, System.DateTime.Now);

            return member;
        }
0
Comment
Question by:WorknHardr
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 total points
ID: 39619983
user  probably null,

wrap it in something like this and see if it runs:

if(user != null){

}

if it still runs then couple of things...
you are invoking the constructor, this article says you shouldnt be doing that..
http://msdn.microsoft.com/en-us/library/1ab7f2be.aspx

check this out:
http://msdn.microsoft.com/en-us/library/System.Web.Security.MembershipUser(v=vs.110).aspx

its actually the object you use when retrieving a membership user e.g.
MembershipUser u = Membership.GetUser(User.Identity.Name);

its been a while since I used Membership, but in essence it is bootstrapped from the config (web.config) so you install the asp.net membership stuff or roll your own... take a look at the second link its got links out to examples...
0
 

Author Closing Comment

by:WorknHardr
ID: 39623197
Thanks, I'm going in the right direction now...
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 39634869
cool, nice one...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now