如何获取登录的用户ID ASP.NET MVC6当前 [英] How to get the current logged in user Id ASP.NET MVC6

查看:190
本文介绍了如何获取登录的用户ID ASP.NET MVC6当前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前用MVC5使用User.Identity.GetUserId()做到了这一点,但似乎并不在这里工作。
该User.Identity不必须的GetUserId()方法

I've done this before with MVC5 using User.Identity.GetUserId() but that doesn't seem to work here. The User.Identity doesnt have the GetUserId() method

我使用Microsoft.AspNet.Identity

I am using Microsoft.AspNet.Identity

推荐答案

我包括使用System.Security.Claims,我可以访问GetUserId()扩展方法

I included using System.Security.Claims and I could access the GetUserId() extension method

注:我有使用Microsoft.AspNet.Identity已经但是不能得到扩展方法。所以我想他们两个人在结合使用彼此

NB: I had the using Microsoft.AspNet.Identity already but couldn't get the extension method. So I guess both of them have to be used in conjunction with one another

using Microsoft.AspNet.Identity;
using System.Security.Claims;

这篇关于如何获取登录的用户ID ASP.NET MVC6当前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆