Solved

Custom ExtendedMemebershipProvider MembershipUser GetUser Object Instance Error?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

751 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