开发者

Retrieve current user login in Sharepoint from a Silverlight application

开发者 https://www.devze.com 2023-01-10 16:18 出处:网络
Is it possible to retrieve the current user login used on sharepoint from an embedded开发者_StackOverflow社区 Silverlight 4 application? On SharePoint 2010

Is it possible to retrieve the current user login used on sharepoint from an embedded开发者_StackOverflow社区 Silverlight 4 application?


On SharePoint 2010

Use client object model (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.web.currentuser.aspx).

Something like:

public void DoStuff()
{
    ClientContext clientContext = ClientContext.Current;

    clientContext.Load(clientContext.Web, s => s.CurrentUser);
    clientContext.ExecuteQueryAsync((sender, args) => {
        var currentUser = clientContext.Web.CurrentUser;
    }, null);
}

On SharePoint 2007

Unfortunatly, the client object model does not exist on SP2007. What I did before is this:

  • Use JQuery SPServices lib to get what I need (http://spservices.codeplex.com/wikipage?title=$().SPServices.SPGetCurrentUser&referringTitle=Documentation)
  • Pass it to my Silverlight application using SL / JS bridge

I guess there is a WebService you can use directly to Silverlight, but I don't know one on the top of my head.


You can use Object models as long as you stay on the Silverlight application within your box. If you want to work in a site located in someone else's system. Then Object Model wont work. Try using Sharepoint's native webservices.

Take a look at Authentication.asmx's Login Method for Forms Authenticated site. You should find it here http://server/site/_vti_bin/Authentication.asmx (look at this sample site http://www.wssdemo.com/Pages/_vti_bin/Authentication.asmx )

For windows authenticated site, you will need to look at NetworkCredentials for getting the current user credentials.

0

精彩评论

暂无评论...
验证码 换一张
取 消