共享点中特定于用户的主题 [英] User specific theme in sharepoint

查看:112
本文介绍了共享点中特定于用户的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我希望在共享点站点中根据用户设置主题.

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

假设用户a将其主题设置为theme1,而用户b登录并将主题设置为theme2.因此,下次用户登录时,他必须必须查看由他设置的主题.即主题a.

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.

谢谢.

Sachin

推荐答案

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

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/.

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

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.

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

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

(免责声明:实际代码要长一些,因为我们使用了按用户缓存,以避免每次用户加载页面时都从UserProfile中读取属性)

(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.

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

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

这篇关于共享点中特定于用户的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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