4

我正在尝试开发一个自定义页面,其中,我正在尝试获取特定出版物中存在的所有组件的列表。

在 aspx 页面的页面加载中,我需要获取当前登录用户的会话。

当我尝试使用代码时

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

我收到以下错误。

Access is denied for the user NT AUTHORITY\NETWORK SERVICE

当我尝试使用代码时

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

我收到以下错误。

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

1.) 在自定义页面中获取会话的正确方法应该是什么?我们可以使用 HttpContext.Current.Request.ServerVariables.Get("REMOTE_USER") 来获取用户吗?

2.) 自定义页面是否应该使用 CoreServices 或 TOM.NET API 从 CM 获取信息。这是首选选项。

4

2 回答 2

4

您不能将 TOM.NET API 用于模板和事件系统以外的进程。请为此使用核心服务 API(您不需要会话)。

我可以将其改写为:您不应该将 TOM.NET API 用于除模板和事件系统之外的进程。从技术上讲这是可能的,但不应该那样使用,这就是引入核心服务的目的。

于 2012-07-11T11:41:29.260 回答
2

如果要使用 Windows 身份验证,可以使用此代码段查看当前用户和附加在 .aspx 中的角色:

<%@ Import Namespace="System.Web.Security" %>  
<% 
string[] rolesArray = Roles.GetRolesForUser();
Response.Write("<strong>LoggedIn User = </strong>" + HttpContext.Current.User.Identity.Name + "<br />");
Response.Write("<strong>Roles LoggedIn User = </strong><br />" + string.Join(",<br />", rolesArray));
%>

也许您需要将其添加到自定义页面的 web.config 中:

<authentication mode="Windows" />
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider" />

希望这会有所帮助,古斯

于 2013-03-29T08:04:33.970 回答