Display logged in user data only in MVC 4 error

PeterZ

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.

McKeymayker

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.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Android: How do I display only the data of the user who is currently logged in?

分類Dev

Error getting products from the logged in user. ASP.NET Core MVC

分類Dev

Allow DISPLAY access for a user not logged on GUI

分類Dev

How to fetch data only if or when the user is logged in with React Js Context API?

分類Dev

ASP.NET MVC: Get user id of currently logged in user

分類Dev

Broadleaf commerce display some product to logged in users only

分類Dev

How to get logged user name/Principal in Spring MVC REST channel?

分類Dev

Undefined index: username error when user has logged out

分類Dev

Add current product to the current logged in user meta data

分類Dev

Only display some data Sonata

分類Dev

Trying to display the User's username in my Navigation Bar once user is logged in?

分類Dev

How to hide one field when the user enter data in another field .NET MVC 4 Razor

分類Dev

SSH to computer with user not logged in

分類Dev

Data Annotations for MVC4

分類Dev

How to authorize user who logged in using external login in Asp.Net MVC

分類Dev

User management with ASP.NET MVC 4

分類Dev

Display global/misc error message to user

分類Dev

how to dynamically display data based on user input

分類Dev

Core Data: display only objectatindex entity

分類Dev

MVC Persisting User Data within the application

分類Dev

Mysql display values if i have only user entered value

分類Dev

How to display an alert only once when user click anywhere

分類Dev

Show record of logged in user in laravel

分類Dev

Show record of logged in user in laravel

分類Dev

Users appear to be logged in as another user

分類Dev

Conditional check if user is logged in Umbraco

分類Dev

NullPointerException while checking logged in user

分類Dev

get current logged user on Plone

分類Dev

Laravel custom redirect if user is not logged in?

Related 関連記事

  1. 1

    Android: How do I display only the data of the user who is currently logged in?

  2. 2

    Error getting products from the logged in user. ASP.NET Core MVC

  3. 3

    Allow DISPLAY access for a user not logged on GUI

  4. 4

    How to fetch data only if or when the user is logged in with React Js Context API?

  5. 5

    ASP.NET MVC: Get user id of currently logged in user

  6. 6

    Broadleaf commerce display some product to logged in users only

  7. 7

    How to get logged user name/Principal in Spring MVC REST channel?

  8. 8

    Undefined index: username error when user has logged out

  9. 9

    Add current product to the current logged in user meta data

  10. 10

    Only display some data Sonata

  11. 11

    Trying to display the User's username in my Navigation Bar once user is logged in?

  12. 12

    How to hide one field when the user enter data in another field .NET MVC 4 Razor

  13. 13

    SSH to computer with user not logged in

  14. 14

    Data Annotations for MVC4

  15. 15

    How to authorize user who logged in using external login in Asp.Net MVC

  16. 16

    User management with ASP.NET MVC 4

  17. 17

    Display global/misc error message to user

  18. 18

    how to dynamically display data based on user input

  19. 19

    Core Data: display only objectatindex entity

  20. 20

    MVC Persisting User Data within the application

  21. 21

    Mysql display values if i have only user entered value

  22. 22

    How to display an alert only once when user click anywhere

  23. 23

    Show record of logged in user in laravel

  24. 24

    Show record of logged in user in laravel

  25. 25

    Users appear to be logged in as another user

  26. 26

    Conditional check if user is logged in Umbraco

  27. 27

    NullPointerException while checking logged in user

  28. 28

    get current logged user on Plone

  29. 29

    Laravel custom redirect if user is not logged in?

ホットタグ

アーカイブ