如何在Tridion中获取目前登录的用户的tcmid? [英] How to get tcmid of currently logged user in Tridion?

查看:167
本文介绍了如何在Tridion中获取目前登录的用户的tcmid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private void Subscribe()
{
EventSystem.Subscribe< User,LoadEventArgs>(GetInfo,EventPhases.Initiated);
}

public void GetInfo(User user,LoadEventArgs args,EventPhases phase)
{
TcmUri id = user.Id;

string name = user.Title;
Console.WriteLine(id.ToString());
Console.WriteLine(name);

}

我写了上面的代码,并在配置文件中添加程序集Tridion服务器,但没有控制台窗口正在登录用户

解决方案

您最初订阅的事件是任何可识别的对象与其任何动作,将触发基本上SDL Tridion CMS中发生的每个事务,所以它不会给你什么时候用户登录(这基本上是所有发生的一切)。 / p>

可能是用户登录后发生的第一件事情之一是它的用户信息和应用程序数据被读取。那么你应该尝试的就是这样的:

  private void Subscribe()
{
EventSystem.Subscribe< User,LoadEventArgs>(GetInfo,EventPhases.Initiated);
}

public void GetInfo(User user,LoadEventArgs args,EventPhases phase)
{
TcmUri id = user.Id;
string name = user.Title;
}

但请记住,这也将由其他操作触发像查看历史记录,检查发布交易和可能更多。我不知道如何将这个动作区分为用户登录的一部分,因为没有特别触发这个事件。



你可能想要检查你是否可以在 LoadEventArgs 中找到任何特定于登录的东西,例如在 ContextVariables EventStack FormerLoadState LoadFlags



编辑:



请注意,事件系统正在SDL Tridion内核中运行,因此您无法从任何地方看到控制台窗口弹出窗口。如果要记录信息,可以包括以下使用语句:

 使用Tridion.Logging ; 

添加引用到 Tridion.Logging.dll 您可以在 .. \Tridion\bin\client 目录中找到。那么你可以在代码中使用下面的日志记录:

  Logger.Write(message ,name,LoggingCategory.General,TraceEventType.Information); 

您将在您的Tridion事件日志中找到(如果您已将日志记录级别设置为显示信息)消息也是如此)。



但是这里最好的选择是调试你的事件系统,所以当触发事件时可以直接检查你的对象。 这里你可以找到一个很好的博客文章关于如何设置事件系统的调试。


    private void Subscribe()
    {
        EventSystem.Subscribe<User, LoadEventArgs>(GetInfo, EventPhases.Initiated);
    }

    public void GetInfo(User user, LoadEventArgs args, EventPhases phase)
    {
        TcmUri id = user.Id;

        string name = user.Title;
        Console.WriteLine(id.ToString());
        Console.WriteLine(name);

    }

I wrote above code and add the assembly in config file in Tridion server but no console window is coming on login of a user

解决方案

The event you were initially subscribing to is the processed phase of any identifiable object with any of its actions, that will trigger basically on every transaction happening in the SDL Tridion CMS, so it won't give you any indication of when a user logs in (it's basically everything which happens all the time).

Probably one of the first things which is happening after a user logs in, is that its user info and application data is read. So what you should try is something along the lines of:

private void Subscribe()
{
    EventSystem.Subscribe<User, LoadEventArgs>(GetInfo, EventPhases.Initiated);
}

public void GetInfo(User user, LoadEventArgs args, EventPhases phase)
{
    TcmUri id = user.Id;
    string name = user.Title;
}

But do keep in mind that this will also be triggered by other actions, things like viewing history, checking publish transactions and possibly a lot more. I don't know how you can distinguish this action to be part of a user login, since there isn't an event triggered specifically for that.

You might want to check out if you can find anything specific for a login in the LoadEventArgs for instance in its ContextVariables, EventStack, FormerLoadState or LoadFlags.

Edit:

Please note that the Event System is running inside the SDL Tridion core, so you won't ever see a console window popup from anywhere. If you want to log information, you can include the following using statement:

using Tridion.Logging;

After adding a reference to the Tridion.Logging.dll which you can find in your ..\Tridion\bin\client directory. Then you can use the following logging statement in your code:

Logger.Write("message", "name", LoggingCategory.General, TraceEventType.Information); 

Which you will find back in your Tridion Event log (provided you have set the logging level to show information messages too).

But probably the best option here is to just debug your event system, so you can directly inspect your object when the event is triggered. Here you can find a nice blog article about how to setup debugging of your event system.

这篇关于如何在Tridion中获取目前登录的用户的tcmid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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