我可以从 Sharepoint 站点上的 Silverlight 用户控件访问 WSS 组吗?

发布于 2024-11-26 13:08:43 字数 604 浏览 3 评论 0原文

我在 MOSS (Sharepoint 2007) 中有一个 Silverlight 控件,我想根据 Sharepoint 中设置的用户角色有条件地启用它。我发现我可以根据

http://<server-url>/_vti_bin/usergroup.asmx

。 aspx" rel="nofollow">MSDN.令我懊恼的是,虽然我可以轻松添加 Web 引用,但我无法找到我必须引用的程序集。有谁知道这是什么集会,以及我是否可以走正确的路线?永远感谢。

编辑 Silverlight 是客户端,所以显然我需要一种从服务器获取 SPUser 和 SPGroup 信息的方法。 WSS 服务似乎没有有用的方法。我现在尝试在 Sharepoint Designer 中创建一个页面并将其用作准 RESTful 服务。这是愚蠢的吗?我希望 Sharepoint 能够提供这项特殊的服务。

编辑 由于 SharePoint 2007 不允许 Silverlight 控件访问服务器端 API 元素(例如 SPUser),因此我提出了一个解决方案,在 InitParameters 中传递标志值。下面发布了。

I have a Silverlight control in MOSS (Sharepoint 2007) which I want to conditionally enable based upon the user roles set in Sharepoint. I found that I may add a Web reference to the UserGroups service with

http://<server-url>/_vti_bin/usergroup.asmx

according to this article on MSDN. To my chagrin, although I can easily add a Web reference, I have not been able to find what assembly I must reference. Does anyone know what assembly this, and whether I may going the correct route? Thanks always.

Edit
Silverlight is client side so apparently I need a way to get the SPUser and SPGroup information from the server. WSS services dont' seem to have a useful method. I'm now trying to make a page in Sharepoint Designer and use it as a quasi RESTful service. Is this folly? I would expect Sharepoint to come with this particular service.

Edit
Since SharePoint 2007 doesn't allow Silverlight Controls to access server side API elements like SPUser, I came up with a solution where I pass flag values in the InitParameters. It is posted below.

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

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

发布评论

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

评论(3

温柔嚣张 2024-12-03 13:08:43

我在 MOSS 中没有太多使用 Silverlight,但是您不能仅引用位于 12Hive/ISAPI 文件夹中的 Microsoft.SharePoint 程序集吗?

然后你可以使用

SPWeb web = SPContext.Current.Web;
SPGroup group = web.SiteGroups[groupName];

I haven't played much with Silverlight in MOSS but can you not just reference the Microsoft.SharePoint assembly located at 12Hive/ISAPI folder?

Then you can use

SPWeb web = SPContext.Current.Web;
SPGroup group = web.SiteGroups[groupName];
谁的新欢旧爱 2024-12-03 13:08:43

可以使用 silverlight 客户端对象模型。
请参阅 http://msdn.microsoft.com/en-us/library/ee538971。 ASPX
但:

第三种可能——修改客户端访问跨域策略
服务器 - 存在安全风险并且在 SharePoint 中不受支持
基金会2010。

因此这取决于您的设置以及您是否愿意开放跨域策略。

Using the silverlight client side object model is possible.
See http://msdn.microsoft.com/en-us/library/ee538971.aspx
But:

A third possibility--modifying client access cross-domain policy on
the server--opens security risks and is not supported in SharePoint
Foundation 2010.

Therefore this depends on your setup and whether you are willing to open up your cross-domain policy..

送君千里 2024-12-03 13:08:43

我发现MOSS(又名SharePoint 2007)没有访问客户端SPUser权限的机制。因此 SilverLight 控件没有直接方法来获取此信息。我的解决方案是修改托管 SilverLight 控件的 WebPart 以包含一个属性,该属性会将该信息作为 InitParams 之一传递给 SilverLight 控件。

目前,Web 上有许多用于托管 SilverLight 控件的 WebPart。这里有几个例子。

代码库
http://silverlightwebpart.codeplex.com/

柯克·埃文斯博客
http:// /blogs.msdn.com/b/kaevans/archive/2008/10/08/hosting-silverlight-in-a-sharepoint-webpart.aspx

有我的 WebPart 和本文中的 WebPart 有明显的相似之处。
http://blogs .msdn.com/b/andreww/archive/2009/03/12/silverlight-web-part-in-sharepoint.aspx

我决定做的是制作 WebPart 本身可配置

public class SecureSilverLightWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
    private int _controlWidth;
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Silverlight Control Width")]
    public int ControlWidth
    {
        get { return _controlWidth; }
        set { _controlWidth = value; }
    }
    private int _controlHeight;
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Silverlight Control Height")]
    public int ControlHeight
    {
        get { return _controlHeight; }
        set { _controlHeight = value; }
    }

    string _silverLightXapPath = string.Empty;
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("SilverLight Xap file path"),
   WebDescription("Enter the SilverLight Xap File Name which will be downloaded at Runtime")]
    public string SilverLightXapPath
    {
        get { return _silverLightXapPath; }
        set { _silverLightXapPath = value; }
    }

    string _controlParameters = "";
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Parameters to SilverLight Application"),
   WebDescription("Enter Key Value Pair Parameters That Needs to be sent to SilverLight Application")]
    public string ControlParameters
    {
        get { return _controlParameters; }
        set { _controlParameters = value; }
    }

    private string _fullAccessGroup = "";
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
     WebDisplayName("Group membership required to enable Silverlight Application"),
     WebDescription("Enter the Sharepoint group required to enable this component.")]
    public string FullAccessGroup
    {
        get { return _fullAccessGroup; }
        set { _fullAccessGroup = value; }
    }

    // This method member checks whether the current
    // SharePoint user is a member of the group, groupName
    private bool IsMember(string groupName)
    {
        bool isMember;
        SPSite site = SPContext.Current.Web.Site;
        SPWeb web = site.OpenWeb();
        try
        {
            isMember = web.IsCurrentUserMemberOfGroup(web.Groups[groupName].ID);
        }
        catch (SPException ex)
        {
            isMember = false;
        }
        finally
        {
            web.Close();
            site.Close();
        }

        return isMember;
    }


    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        if (_controlHeight != 0 && _controlWidth != 0 && _silverLightXapPath != string.Empty)
        {
            Silverlight sl = new Silverlight();

            sl.ID = "SlCoffee";

            if (ConfigurationSettings.AppSettings != null)
            {
                //In the Web.config for the Sharepoint site I have a key in the AppSettings
                //pointing to the where the Xap files are saved. Something
                //like <add key="SITEURL" value="http://MyServer:43746/XapFiles/" />
                if (ConfigurationSettings.AppSettings["SITEURL"] != string.Empty)
                {
                    string url = ConfigurationSettings.AppSettings["SITEURL"];
                    sl.Source = url + _silverLightXapPath;
                }
            }

            sl.Width = new Unit(_controlWidth);

            sl.Windowless = true;

            sl.Height = new Unit(_controlHeight);


            int SettingCount = ConfigurationSettings.AppSettings.Count;
            StringBuilder SB = new StringBuilder();

            //Optional
            for (int index = 0; index < SettingCount; index++)
            {
                //Most of the InitParams are kept in the AppSettings. You probably
                //wouldn't send all of your AppSettings to the control like this.
                if (ConfigurationSettings.AppSettings.GetKey(index).StartsWith("client"))
                {
                    SB.Append(ConfigurationSettings.AppSettings.GetKey(index));
                    SB.Append("=");
                    SB.Append(ConfigurationSettings.AppSettings[index]);
                    SB.Append(",");
                }
            }

            //This is the place in the code where SPUser and Group information is
            //sent to the SilverLight control hosted by this WebPart.
            SB.Append("UserId=" + SPContext.Current.Web.CurrentUser + ",");
            SB.Append(_controlParameters);

            //Security portion
            SB.Append("FullControl=" + IsMember(FullAccessGroup));

            sl.InitParameters = SB.ToString();

            Controls.Add(sl);
        }

    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        ScriptManager sm = ScriptManager.GetCurrent(Page);

        if (sm == null)
        {
            sm = new ScriptManager();
            Controls.AddAt(0, sm);
        }
    }

    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
        if (_controlHeight == 0 || _controlWidth == 0 || _silverLightXapPath == string.Empty)
        {
            writer.Write("<h3>Please Configure Web Part Properties<h3>");
        }
    }
}

接下来在 SilverLight 控件中我使用 Initparameters

/// <summary>
/// Handles the Loaded event of the MainPage control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    if(UserMayEdit() )
    {
        // User is a member of the group set up in configuration of the WebPart.
        // enable any controls accordingly.
        TabItem_Backlog.IsEnabled = true;
    }
    else
    {
        // User is not a member - disable.
        TabItem_Backlog.IsEnabled = false;
        TabItem_Approved.IsSelected = true;
    }

    //...
}

/// <summary>
/// Checks input parameters to determine whether
/// users the may edit
/// </summary>
/// <returns></returns>
private bool UserMayEdit()
{
    bool bCardEditor = false;

    try
    {
        if (application.AppConfiguration["FullControl"].ToUpper() == "TRUE")
        {
            bCardEditor = true;
        }
    }
    catch (KeyNotFoundException)
    {
        MessageBox.Show("Please configure the component's security settings to enable the Active tab.", "PMDG Cards", MessageBoxButton.OK);
    }

    return bCardEditor;
}

SilverLight UserControl 中的字典存在于 App.xaml.cs 中,如下所示

public partial class App : Application
{
    public static string UserID = string.Empty;

    public IDictionary<string, string> AppConfiguration;
    public App()
    {
        this.Startup += this.Application_Startup;
        this.Exit += this.Application_Exit;
        this.UnhandledException += this.Application_UnhandledException;

        InitializeComponent();
    }

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        AppConfiguration = e.InitParams;
        UserID = e.InitParams["UserId"];
        this.RootVisual = new MainPage();
    }
    //...
}

我能说什么呢?有用。

I found that MOSS (a.k.a. SharePoint 2007) has no mechanism for accessing SPUser permission the client. Hence SilverLight controls have no direct means to obtain this information. My solution was to modify the WebPart hosting the SilverLight control to include a property, which would pass that information to the SilverLight control as one of the InitParams.

Currently there are many WebParts for hosting a SilverLight control available on the Web. Here are a few examples.

CodePlex
http://silverlightwebpart.codeplex.com/

Kirk Evans Blog
http://blogs.msdn.com/b/kaevans/archive/2008/10/08/hosting-silverlight-in-a-sharepoint-webpart.aspx

There are noticable similarities with my WebPart and the one in this article.
http://blogs.msdn.com/b/andreww/archive/2009/03/12/silverlight-web-part-in-sharepoint.aspx

What I decided to do is make the WebPart itself configurable

public class SecureSilverLightWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
    private int _controlWidth;
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
    WebDisplayName("Silverlight Control Width")]
    public int ControlWidth
    {
        get { return _controlWidth; }
        set { _controlWidth = value; }
    }
    private int _controlHeight;
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Silverlight Control Height")]
    public int ControlHeight
    {
        get { return _controlHeight; }
        set { _controlHeight = value; }
    }

    string _silverLightXapPath = string.Empty;
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("SilverLight Xap file path"),
   WebDescription("Enter the SilverLight Xap File Name which will be downloaded at Runtime")]
    public string SilverLightXapPath
    {
        get { return _silverLightXapPath; }
        set { _silverLightXapPath = value; }
    }

    string _controlParameters = "";
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Parameters to SilverLight Application"),
   WebDescription("Enter Key Value Pair Parameters That Needs to be sent to SilverLight Application")]
    public string ControlParameters
    {
        get { return _controlParameters; }
        set { _controlParameters = value; }
    }

    private string _fullAccessGroup = "";
    [Personalizable(PersonalizationScope.Shared), WebBrowsable(true),
     WebDisplayName("Group membership required to enable Silverlight Application"),
     WebDescription("Enter the Sharepoint group required to enable this component.")]
    public string FullAccessGroup
    {
        get { return _fullAccessGroup; }
        set { _fullAccessGroup = value; }
    }

    // This method member checks whether the current
    // SharePoint user is a member of the group, groupName
    private bool IsMember(string groupName)
    {
        bool isMember;
        SPSite site = SPContext.Current.Web.Site;
        SPWeb web = site.OpenWeb();
        try
        {
            isMember = web.IsCurrentUserMemberOfGroup(web.Groups[groupName].ID);
        }
        catch (SPException ex)
        {
            isMember = false;
        }
        finally
        {
            web.Close();
            site.Close();
        }

        return isMember;
    }


    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        if (_controlHeight != 0 && _controlWidth != 0 && _silverLightXapPath != string.Empty)
        {
            Silverlight sl = new Silverlight();

            sl.ID = "SlCoffee";

            if (ConfigurationSettings.AppSettings != null)
            {
                //In the Web.config for the Sharepoint site I have a key in the AppSettings
                //pointing to the where the Xap files are saved. Something
                //like <add key="SITEURL" value="http://MyServer:43746/XapFiles/" />
                if (ConfigurationSettings.AppSettings["SITEURL"] != string.Empty)
                {
                    string url = ConfigurationSettings.AppSettings["SITEURL"];
                    sl.Source = url + _silverLightXapPath;
                }
            }

            sl.Width = new Unit(_controlWidth);

            sl.Windowless = true;

            sl.Height = new Unit(_controlHeight);


            int SettingCount = ConfigurationSettings.AppSettings.Count;
            StringBuilder SB = new StringBuilder();

            //Optional
            for (int index = 0; index < SettingCount; index++)
            {
                //Most of the InitParams are kept in the AppSettings. You probably
                //wouldn't send all of your AppSettings to the control like this.
                if (ConfigurationSettings.AppSettings.GetKey(index).StartsWith("client"))
                {
                    SB.Append(ConfigurationSettings.AppSettings.GetKey(index));
                    SB.Append("=");
                    SB.Append(ConfigurationSettings.AppSettings[index]);
                    SB.Append(",");
                }
            }

            //This is the place in the code where SPUser and Group information is
            //sent to the SilverLight control hosted by this WebPart.
            SB.Append("UserId=" + SPContext.Current.Web.CurrentUser + ",");
            SB.Append(_controlParameters);

            //Security portion
            SB.Append("FullControl=" + IsMember(FullAccessGroup));

            sl.InitParameters = SB.ToString();

            Controls.Add(sl);
        }

    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        ScriptManager sm = ScriptManager.GetCurrent(Page);

        if (sm == null)
        {
            sm = new ScriptManager();
            Controls.AddAt(0, sm);
        }
    }

    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
        if (_controlHeight == 0 || _controlWidth == 0 || _silverLightXapPath == string.Empty)
        {
            writer.Write("<h3>Please Configure Web Part Properties<h3>");
        }
    }
}

Next in the SilverLight control I use the Initparameters

/// <summary>
/// Handles the Loaded event of the MainPage control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    if(UserMayEdit() )
    {
        // User is a member of the group set up in configuration of the WebPart.
        // enable any controls accordingly.
        TabItem_Backlog.IsEnabled = true;
    }
    else
    {
        // User is not a member - disable.
        TabItem_Backlog.IsEnabled = false;
        TabItem_Approved.IsSelected = true;
    }

    //...
}

/// <summary>
/// Checks input parameters to determine whether
/// users the may edit
/// </summary>
/// <returns></returns>
private bool UserMayEdit()
{
    bool bCardEditor = false;

    try
    {
        if (application.AppConfiguration["FullControl"].ToUpper() == "TRUE")
        {
            bCardEditor = true;
        }
    }
    catch (KeyNotFoundException)
    {
        MessageBox.Show("Please configure the component's security settings to enable the Active tab.", "PMDG Cards", MessageBoxButton.OK);
    }

    return bCardEditor;
}

The Dictionary in the SilverLight UserControl exists in the App.xaml.cs as seen here

public partial class App : Application
{
    public static string UserID = string.Empty;

    public IDictionary<string, string> AppConfiguration;
    public App()
    {
        this.Startup += this.Application_Startup;
        this.Exit += this.Application_Exit;
        this.UnhandledException += this.Application_UnhandledException;

        InitializeComponent();
    }

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        AppConfiguration = e.InitParams;
        UserID = e.InitParams["UserId"];
        this.RootVisual = new MainPage();
    }
    //...
}

What can I say? It works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文