0

When a user logs in i want them to see only db entry that match there id on the index page

im currently using the below which works as fare as getting the correct data but get a error when i run the project

Code:

public ActionResult Index()
{
return View(db.UserProfiles.ToList().Where(u => u.UserId ==
(int)Membership.GetUser().ProviderUserKey));
}

Error: nullreferenceexception was unhandled by the user code Object reference not set to an instance of an object.

PeterZ
  • 137
  • 2
  • 13
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – DavidG Oct 07 '14 at 12:02

1 Answers1

1

To fully implement authorization in MVC4 you have to do a little more work then that. I found (and used) a great article for this problem : http://primaryobjects.com/CMS/Article147.aspx[^]

Also you try put [Authorize] above the index call method.

McKeymayker
  • 373
  • 2
  • 11
  • Thanks for all your help, the reason for the error was not having [Authorize] above the index. – PeterZ Oct 07 '14 at 12:06