views:

748

answers:

3

I'm new to Sharepoint and have tried googeling this, so sorry if I'm just being dumb.

I have written a webservice that takes a username and returns some company related information about the user.

I found on google that one of the best ways to use this information is be creating a data store in Sharepoint designer.

I have managed to get it to work by adding a default paramter, but I need to pass in the username of the person logged in.

I found that if you select the parameter source to be Server Variable and use LOGIN USER as the name it should send that across but it's sending the default value all the time.

What am I doing wrong?

Many thanks for your help.

Andi

A: 

Try LOGON_USER

Here's a complete list of server variables along with descriptions.. http://www.w3schools.com/asp/coll_servervariables.asp

CodeToaster
Thanks for the suggestion.Not working though. It seems that nothing but the default value is being sent.Whether that's becauseLOGON_USER is empty or someother reason I do not know.
Andi McLean
A: 

In a ASP.NET application/process you can retrieve the current identity in different ways:

using System.Security.Principal;

...

string username1 = HttpContext.Current.User.Identity.Name;
string username2 = WindowsIdentity.GetCurrent().Name;

Your webservice should also be setup to use Windows-Auth:

<authentication mode="Windows" />
<identity impersonate="true"/>
Henrik
Thanks HenrikI have managed to do it with writing a webpart and using code like you suggest. I was trying to do it without writing any code and just using sharepoint designer as I had seen recommend.
Andi McLean
+1  A: 

It is probably best to use the official SharePoint syntax for retrieving the current user.

SPContext.Current.Web.CurrentUser;

MSDN Documentation for CurrentUser.

Related article on StackOverflow.

Muhimbi
True. But only if the context is available. For webparts, SharePoint deployed webservices, ...If you have a plain ASP.NET application which just uses the SharePoint object-model I think there is no SPContext.
Henrik