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:

Regex Email validation in c# dot net core

 Use this regex /^_?[a-zA-Z0-9]([a-zA-Z0-9]*[._+-])*[a-zA-Z0-9_]+@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*\.[A-...