Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть How to get authenticated user identity name in asp net web api

  • kudvenkat
  • 2016-12-13
  • 131572
How to get authenticated user identity name in asp net web api
get logged in user name in asp net web apiweb api get current user idweb api controller get current userweb api controller get logged in userasp.net web api user identityweb api user.identity.name nullweb api 2 get current userapicontroller.user property
  • ok logo

Скачать How to get authenticated user identity name in asp net web api бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно How to get authenticated user identity name in asp net web api или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку How to get authenticated user identity name in asp net web api бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео How to get authenticated user identity name in asp net web api

Text version of the video
http://csharp-video-tutorials.blogspo...

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

Slides
http://csharp-video-tutorials.blogspo...

All ASP .NET Web API Text Articles and Slides
http://csharp-video-tutorials.blogspo...

All ASP .NET Web API Videos
   • ASP.NET Web API tutorial for beginners  

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...

All Dot Net and SQL Server Tutorials in Arabic
   / kudvenkatarabic  

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 retrieve user details

User.Identity.IsAuthenticated - Returns true or false depending on whether the user is authenticated
User.Identity.AuthenticationType - Authentication Type used
User.Identity.Name - Logged in username

RequestContext.Principal.Identity.IsAuthenticated - Returns true or false depending on whether the user is authenticated
RequestContext.Principal.Identity.AuthenticationType - Authentication Type used
RequestContext.Principal.Identity.Name - Logged in username

Instead of using User.Identity, we can also use RequestContext.Principal.Identity

To see what the respective properties return, set a breakpoint in the Get() method of Employees controller and run the application in debug mode. Navigate to Login page and login. On the Data.html page click "Load Employees" button. When the execution pauses at the breakpoint, open Immediate Window and type the above properties one by one and press enter. To open immediate window, in Visual Studio select Debug - Windows - Immediate.

Now let us see what these properties return if we are not logged in.
1. Add a new Empty Web API 2 Controller to the EmployeeService project. Name it TestController.
2. Copy and paste the following code in TestController.

using System.Web.Http;
namespace EmployeeService.Controllers
{
public class TestController : ApiController
{
public string Get()
{
return "Hello from TestController";
}
}
}

3. Set a breakpoint on the Get() method in TestController. Run the application in Debug mode and navigate to /api/Test. When the execution pauses at the breakpoint, open Immediate Window and type the above properties one by one and press enter.

Since we are not logged in, notice IsAuthenticated property returns false. Since we are not authenticated AuthenticationType and Name properties return NULL.

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]