Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Custom ExtendedMemebershipProvider MembershipUser GetUser Object Instance Error?

Posted on 2013-11-01
3
Medium Priority
?
428 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
[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
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 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