After some time i finally figured it out ...
the best way to do so is to use the WebSecurty class
var memberId = WebSecurity.GetUserId(User.Identity.Name);
and don't forget to add
on top of your controller :)
I think the easiest way is...
var userId = (Guid)Membership.GetUser(User.Identity.Name).ProviderUserKey;
No data attributes needed :)
The easiest way to get the Current User Id in Asp.Net MVC 4 is
Or, just to add to my previous comment, you can also use -
Thank you!! this helped me a lot.
I tried these both code
ViewBag.UserId = WebSecurity.CurrentUserId;
ViewBag.UserId = (int)WebSecurity.CurrentUserId;
but I got same error "You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site."
please help, thx
solve my self :
adding [InitializeSimpleMembership] on the top of controller name, and include Filter using MvcMovie.Filters;
Then use extension methods:
how to implement this code to my controller ?where i should write this code ?