Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Custom ExtendedMemebershipProvider MembershipUser GetUser Object Instance Error?

Posted on 2013-11-01
3
Medium Priority
?
431 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

824 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