Search code examples
tridiontridion-2011

Get the Session for the currently logged in User - Custom Pages


I am trying to develop a Custom Page, wherein, I am trying to get a List of all Components that are present in a particular publication.

In the Page Load of the aspx page, I need to get the session for the currently logged in User.

When I try to use the code

    Session currSession = new Session();
    Response.Write(currSession.User.Id);

I get the following error.

Access is denied for the user NT AUTHORITY\NETWORK SERVICE

When I try the code with

Session currSession = new Session(WindowsIdentity.GetCurrent());
Response.Write(currSession.User.Id);

I get the following error.

The name 'WindowsIdentity' does not exist in the current context

1.) What should be a proper method to get the session in a Custom Page ? Can we use the HttpContext.Current.Request.ServerVariables.Get("REMOTE_USER"), to get the user.

2.) Should Custom Page use CoreServices or TOM.NET API's to get information from CM. Which is the preferred option.


Solution

  • You cannot use the TOM.NET API for processes other than Templates and Event System. Please use the Core Service API instead for this (there you won't need a Session).

    I might rephrase this to: you should not use the TOM.NET API for processes other than Templates and Event System. As technically it is possible, but it's not supposed to be used like that, that is what the core service is introduced for.