[Solved] Forms Authentication User.Identity.GetUserId return null in ASP.Net MVC

Last Reply 4 days ago By Mudassar

Posted 4 days ago

I just followed your tutorial on Simple User Login Form with Entity Framework Database in ASP.Net MVC. Now I want User Id to perform some operation. User.Identity.GetUserId() always return null.

Posted 4 days ago

This is Custom Forms Authentication and hence the standard GetUserId method won't work.

You can get UserName by using User.Indentity.Name

And if you need UserId in this property you will need to set UserId in Forms Authentication ticket.

 FormsAuthentication.SetAuthCookie(user.UserId, user.RememberMe);


I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html