Re: How to get user id guid



Great, if that works, then cool. Is that a SharePoint feature, or something
else?

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"Keith Harris" <KeithHarris@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:DBCB66A4-1B8F-40E5-BB02-8F42DB06020C@xxxxxxxxxxxxxxxx
I found a much easier way to get the user id is to use the
UserProfileManager
to get a UserProfile object which contains the user's id. Here's the
code:

UserProfileManager upm = new UserProfileManager(PortalContext.Current);
if (upm != null)
{
UserProfile up =
upm.GetUserProfile(HttpContext.Current.User.Identity.Name);
if (up != null)
return up.ID;
}


"Joe Kaplan (MVP - ADSI)" wrote:

Your p/invoke looks good to me. I think I'd change it throw a
System.ComponentModel.Win32Exception using the result from
GetLastWin32Error
if there is a failure, but I don't think that is crucial.

You might try www.pinvoke.net to see if they've wrapped this API or also
perhaps try the framework.interop newgroup. If I get a chance to play
with
later today, I'll try it myself and see what can be made to happen.

Joe K.

"Keith Harris" <KeithHarris@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F034BED1-944E-483C-AB84-1DA773934455@xxxxxxxxxxxxxxxx
Hi Joe,
I found the information I needed to use the secur32 dll but when I try
to
convert the username to a unique id, it's always blank. Here's the
code I
use:

///////////////////////////////////////////////////////////////////////////////
#region setup call to dll
[Flags]
public enum EXTENDED_NAME_FORMAT
{
NameUnknown = 0,
NameFullyQualifiedDN = 1,
NameSamCompatible = 2,
NameDisplay = 3,
NameUniqueId = 6,
NameCanonical = 7,
NameUserPrincipal = 8,
NameCanonicalEx = 9,
NameServicePrincipal = 10,
NameDnsDomain = 12
}
///////////////////////////////////////////////////////////////////////////////
[DllImport("secur32", CharSet=CharSet.Auto, SetLastError=true)]
static extern bool TranslateName(string lpAccountName,
EXTENDED_NAME_FORMAT AccountNameFormat, EXTENDED_NAME_FORMAT
DesiredNameFormat, System.Text.StringBuilder lpTranslatedName, ref int
nSize);
#endregion

///////////////////////////////////////////////////////////////////////////////
string PrintName(string userName, EXTENDED_NAME_FORMAT fromFmt)
{
StringBuilder translatedName = new StringBuilder(256);
int nSize = translatedName.Capacity;
if (!TranslateName(userName, fromFmt,
EXTENDED_NAME_FORMAT.NameUniqueId, translatedName, ref nSize))
return Marshal.GetLastWin32Error().ToString();
else
return translatedName.ToString();
}

///////////////////////////////////////////////////////////////////////////////
protected void Page_Load(object sender, EventArgs e)
{
string username = HttpContext.Current.User.Identity.Name;
Response.Write(PrintName(username,
EXTENDED_NAME_FORMAT.NameDnsDomain));
}

///////////////////////////////////////////////////////////////////////////////

My web site is using Integrated Windows authentication with Digest
authentication selectec and Anonymous access off.

I appreciate any ideas you might have.

Thanks for you help,
-Keith

"Joe Kaplan (MVP - ADSI)" wrote:

You might consider p/invoking the TranslateName API or something like
that.

Agreed that if you want to use the authenticated user's credentials to
access AD via LDAP, you will need Kerberos delegation and that can be
a
little painful at times. It is definitely possible though.

Joe K.

"Keith Harris" <KeithHarris@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:9BA9064F-1EA0-45CB-878F-A5B57F2A492B@xxxxxxxxxxxxxxxx
Hi

I am developing a SSO web part between a SharePoint site and my web
application. I would like to accomplish this by passing the guid of
the
currently logged on user to the target web site.

It seems the only way to get this id is by performing an AD lookup
for
the
current logged in user. Is that correct or am I missing something?

Because of the difficulty in setting up DirectoryServices access
from
an
SPS
web part, I would like to discover an easier way of doing this.

Any help is greatly appreciated.
Thanks.








.



Relevant Pages

  • Re: How to get user id guid
    ... Joe Kaplan-MS MVP Directory Services Programming ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... UserProfileManager upm = new UserProfileManager; ... I am developing a SSO web part between a SharePoint site and my web ...
    (microsoft.public.dotnet.security)
  • Re: Domain registration requirement in federated web sso with fore
    ... Thanks a lot Joe for this useful information. ... We have some applications, written in non microsoft languages like Java, ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... internet, then the DNS entries for the resources will need to be ...
    (microsoft.public.windows.server.active_directory)
  • Re: Error setting DirecotrySearchers new ExtendedDN
    ... Thanks Joe, but now I'm worried and confused. ... 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, ... The .NET Framework does not support all versions of every platform. ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ...
    (microsoft.public.platformsdk.security)
  • Re: ADAM Authentication
    ... Only using ADAM for testing a proof-of-concept; ... "Joe Kaplan" wrote: ... Note that using S.DS for authentication may cause you scalability problems ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ...
    (microsoft.public.windows.server.active_directory)
  • Re: Authentication exception calling ActiveDirectory.Domain.GetCom
    ... Joe Kaplan-MS MVP Directory Services Programming ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... identity to a domain account. ... rights. ...
    (microsoft.public.dotnet.framework.aspnet.security)

Quantcast