sharepoint 中的用户特定主题

发布于 2024-08-19 14:47:16 字数 168 浏览 4 评论 0原文

我有一个要求,在我的共享点网站中我想根据用户设置主题。

例如,假设用户 a 将其主题设置为 theme1,而用户 b 登录并将主题设置为 theme2。因此,当用户下次登录时,他必须看到他设置的主题。即主题a。

谁能告诉我最好的方法是什么?

提前致谢。

萨钦

I have a requirment where in my sharepoint site I want to set the theme according to user.

for e.g lets say if user a set his theme as theme1 and the user b logs in and set theme to theme2. So next time when user a log in he must have to see the theme set by him. I.e theme a.

Can any one tell me what will be the best approch to do it.

Thanks in advance.

Sachin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

z祗昰~ 2024-08-26 14:47:16

我曾经有过类似的需求。就我而言,他们希望用户能够更改 MOSS 门户的“颜色布局”(因此布局和字体相同,但每个主题的背景颜色和图像颜色不同)。我创建了一个“基本主题”,其中包含作为单个 CSS 文件的完整布局(提供的主题之一)。然后我创建了其他主题,例如“blue.css”、“red.css”、“green.css”等,并将所有这些文件放入 portal/ourthemes/ 中。

我们希望用户能够选择他们的主题,因此我们创建了一个新的用户配置文件属性“CurrentTheme”(Sharepoint 中央管理 -> 共享服务 -> 用户配置文件和属性 -> 添加配置文件属性),其定义为带有预定义选项列表的字符串。

然后我创建了一个简单的 ASP.Net 控件,其呈现为

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
  Dim oProf As Microsoft.Office.Server.UserProfiles.UserProfile = Microsoft.Office.Server.UserProfiles.ProfileLoader.GetProfileLoader.GetUserProfile()
  Dim UserTheme As String
  Try
    If oProf.Item("CurrentTheme") IsNot Nothing Then
      UserTheme = oProf.Item("CurrentTheme").Value.ToString()
    Else
      UserTheme = "blue"
    End If
  Catch ex As Exception
    'shouldn't fail if we don't know the value
    UserTheme = "blue" 'a default value for users who dont have a theme yet
  End Try

  writer.WriteLine("<link rel='stylesheet' type='text/css' href='/portal/ourthemess" & Trim(UserTheme) & ".css' />")
End Sub

(免责声明:实际代码有点长,因为我们使用每个用户缓存来避免每次用户加载页面时从 UserProfile 读取属性)

然后我将此控件放入为该门户创建的母版页中。

编辑:为了进行缓存,我们创建了一个包含用户名并将生成的文本存储在其中的缓存键。结果是这样的:

Dim KeyName As String = Page.User.Identity.Name & "_CurrentTheme"
If (Not Me.Page.Cache.Item(KeyName) Is Nothing) Then 
   writer.Write(Page.Cache.Item(KeyName).ToString)
Else 
  '...code posted previously goes in here

  'at the end
  Me.Page.Cache.Add(KeyName, _
              AllContentRenderedInPreviousCodeAsString, _
              Nothing, _
              Caching.Cache.NoAbsoluteExpiration, _
              Caching.Cache.NoSlidingExpiration, _
              Caching.CacheItemPriority.Low, Nothing)
End If

I had a similar requirement once. In my case they wanted users to be able to change the "color layout" of a MOSS portal (so the layout and fonts was the same, but background color and colors of images were different in each theme). I created a "base theme" which included a complete layout (one of the provided themes) as a single CSS file. Then I created additional themes, such as "blue.css", "red.css", "green.css" et cetera and put all those files in portal/ourthemes/.

We wanted the users to be able to choose their theme, so we created a new user profile property "CurrentTheme" (Sharepoint Central Administration -> Shared services -> User profiles and properties -> Add profile property) which was defined as string with a pre-defined list of choices.

Then I created a simple ASP.Net control which rendered as

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
  Dim oProf As Microsoft.Office.Server.UserProfiles.UserProfile = Microsoft.Office.Server.UserProfiles.ProfileLoader.GetProfileLoader.GetUserProfile()
  Dim UserTheme As String
  Try
    If oProf.Item("CurrentTheme") IsNot Nothing Then
      UserTheme = oProf.Item("CurrentTheme").Value.ToString()
    Else
      UserTheme = "blue"
    End If
  Catch ex As Exception
    'shouldn't fail if we don't know the value
    UserTheme = "blue" 'a default value for users who dont have a theme yet
  End Try

  writer.WriteLine("<link rel='stylesheet' type='text/css' href='/portal/ourthemess" & Trim(UserTheme) & ".css' />")
End Sub

(Disclaimer: the actual code was a bit longer, because we used caching per-user to avoid reading the property from UserProfile every time user loaded the page)

Then I put this control in the master page created for that portal.

EDIT: To do the caching, we created a cache key which contained user name and stored the generated text in there. The result was something like this:

Dim KeyName As String = Page.User.Identity.Name & "_CurrentTheme"
If (Not Me.Page.Cache.Item(KeyName) Is Nothing) Then 
   writer.Write(Page.Cache.Item(KeyName).ToString)
Else 
  '...code posted previously goes in here

  'at the end
  Me.Page.Cache.Add(KeyName, _
              AllContentRenderedInPreviousCodeAsString, _
              Nothing, _
              Caching.Cache.NoAbsoluteExpiration, _
              Caching.Cache.NoSlidingExpiration, _
              Caching.CacheItemPriority.Low, Nothing)
End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文