创建一个方法并使用 ASP.NET 内联表达式调用此方法,如下所示。
IF语言是VB
<script runat="server">
Public Function IsUserAdmin() As Boolean
Dim uinfo As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
If uinfo.UserID <> -1 Then
If uinfo.IsInRole(DotNetNuke.Entities.Portals.PortalSettings.Current.AdministratorRoleName) Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function
</script>
和 ASP.NET 内联表达式是
<% If IsUserAdmin() Then%>
<p>Only administrators can see this!</p>
<% End If%>
如果语言是C#
<script runat="server">
public bool IsUserAdmin()
{
DotNetNuke.Entities.Users.UserInfo uinfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
if (uinfo.UserID != -1)
{
if (uinfo.IsInRole(DotNetNuke.Entities.Portals.PortalSettings.Current.AdministratorRoleName))
return true;
else
return false;
}
else
{
return false;
}
}
</script>
和 ASP.NET 内联表达式是
<% if (IsUserAdmin()) %>
<%
{ %>
<p>Only administrators can see this!</p>
<% } %>