Thursday, September 1, 2016

Get current user id in MVC

Getting current users id has been made very simple with Microsoft.AspNet.Identity.Core nuget package,

First off install the nuget package
Install-Package Microsoft.AspNet.Identity.Core


Now add this using directive in class
using Microsoft.AspNet.Identity;

And finally fetch the current users id by
HttpContext.Current.User.Identity.GetUserId();

No comments:

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...