如何从asp.net MVC中的FormsAuthentication页面获取用户ID? [英] howto get the user id from a FormsAuthentication page in asp.net MVC?

查看:135
本文介绍了如何从asp.net MVC中的FormsAuthentication页面获取用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个使用FormsAuthentication的网页.现在我需要获取用户的用户ID(如果用户已登录)

如何获得这些?我试图通过FormsAuthentication访问它,但是没有方法喜欢:getUserId()

有什么解决方案吗? 顺便说一句,我不需要我的控制器中的ID.

解决方案

if (HttpContext.Current.User.Identity.IsAuthenticated)
{
    var id = HttpContext.Current.User.Identity.Name;
    // Do stuf...
}

i made a webpage which use FormsAuthentication. now i need to get the user id of the user (if a user is logged in)

how to get these? i tryed to access it via the FormsAuthentication but there is no method liks: getUserId()

any solutions? by the way, i need the id in my controller not in my view.

解决方案

if (HttpContext.Current.User.Identity.IsAuthenticated)
{
    var id = HttpContext.Current.User.Identity.Name;
    // Do stuf...
}

这篇关于如何从asp.net MVC中的FormsAuthentication页面获取用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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