获取Umbraco 7.3.5版的当前用户

Ogg*_*las 6 c# asp.net umbraco asp.net-web-api

我正在尝试访问登录的Umbraco用户,而不是成员,但我无法让它工作.

我尝试过以下方法但没有工作,它们都返回null:

umbraco.BusinessLogic.User.GetCurrent()
UmbracoContext.UmbracoUser
UmbracoContext.Security.CurrentUser
umbraco.helper.GetCurrentUmbracoUser()
Run Code Online (Sandbox Code Playgroud)

我可以使用以下代码访问用户,例如Name:

UmbracoContext.Application.Services.UserService.GetByEmail("name@company.com").Name
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这个代码作为用户和成员登录,只有用户,只有成员而根本没有登录,它总是返回相同的结果,null.

我已经在SurfaceController和UmbracoApiController中尝试了相同结果的代码.获取登录成员没有问题有没有Membership.GetUser();其他人经历过这个?

使用:Umbraco版本7.3.5汇编:1.0.5858.25602

Rya*_*ugh 10

是的,我曾尝试以多种方式访问​​当前的后端用户,并发现唯一的方法是:

var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
if (userTicket != null)
{
    var currentUser = ApplicationContext.Services.UserService.GetByUsername(userTicket.Name);
}
Run Code Online (Sandbox Code Playgroud)


Pro*_*ion 5

我昨天刚刚实现了一些代码来让当前用户使用:

UmbracoContext.Current.Security.CurrentUser
Run Code Online (Sandbox Code Playgroud)

那不列为您尝试过的选项之一吗?