Solved

Custom ExtendedMemebershipProvider MembershipUser GetUser Object Instance Error?

Posted on 2013-11-01
3
427 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 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

636 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