【问题标题】:How can I get the current Umbraco user in a Media.AfterSave event handler?如何在 Media.AfterSave 事件处理程序中获取当前 Umbraco 用户?
【发布时间】:2012-11-16 15:38:02
【问题描述】:

当我在 umbraco 中保存媒体文件时,我会收到 aftersave 事件,但我不知道如何在这种情况下获取当前用户。

活动: http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events

我试过了,但没有用: http://our.umbraco.org/forum/developers/extending-umbraco/5317-current-login-user

【问题讨论】:

    标签: c# umbraco


    【解决方案1】:

    我认为只是:

    User currentUser = User.GetCurrent();
    

    (不过我还没有测试过)

    【讨论】:

    • 看起来这在 v 7.x 中已被弃用。请改用 UserService。 (来自视觉工作室的消息)这里有一个关于使用 UserService 的试验的讨论 - our.umbraco.org/forum/developers/api-questions/… - 看起来这个答案仍然是首选。
    【解决方案2】:

    如果@Douglas Ludlow 的解决方案不起作用,试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-21
      • 2015-10-17
      • 2013-05-06
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多