How to get authenticated user identity name in asp net web api

Video ready, click here to close ×


Text version of the video
http://csharp-video-tutorials.blogspot.com/2016/12/how-to-get-authenticated-user-identity.html

Slides
http://csharp-video-tutorials.blogspot.com/2016/12/how-to-get-authenticated-user-identity_13.html

All ASP .NET Web API Text Articles and Slides
http://csharp-video-tutorials.blogspot.com/2016/09/aspnet-web-api-tutorial-for-beginners.html

All ASP .NET Web API Videos

Video ready, click here to close ×

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd

All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists

In this video we will discuss how to get authenticated user identity name in asp.net web api and display it on the web page.

We want to display the logged in username on the web page

On the Login.html page, store the username in the browser local storage. The success() function is called when the user is successfully logged in. The response that we get from the server includes userName property which has the userName that is used to login. We are storing the logged in username in the broswer localstorage using the key userName.

success: function (response) {
localStorage.setItem(“accessToken”, response.access_token);
localStorage.setItem(“userName”, response.userName);
window.location.href = “Data.html”;
},

On the Data.html page include the following span element just below the “Load Employees” button. We will use this span element to display the logged in username.
[span id=”spanUsername” class=”text-muted”][/span]

Step 3 : On the Data.html page, in $(document).ready() function include the following line of jQuery code to retrieve and display the logged in username.
$(‘#spanUsername’).text(‘Hello ‘ + localStorage.getItem(‘userName’));

How to get logged in user identity details in ASP.NET Web API controller
From the ASP.NET Web API controller use the User.Identity object to…

source

12 comments

Leave a Reply

Your email address will not be published. Required fields are marked *