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 obfuscate email

 Use this code in C# to obfuscate email using regex // Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compile...