Logo 
Search:

MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

User Account Look-Ups in SharePoint 2007

  Asked By: Sandy    Date: Jan 24    Category: MOSS    Views: 1554

I am integrating ASP.NET application into sharepoint
..i want username who
logged into sharepoint site .so that i can use it in
ASP.NET application .

could annyone please suggest me possible solution for
this

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Shushma Zariwala     Answered On: Jan 24

Use following code
check for login user  is avaialbe in sharepoint  or not?
-----------------------------------------------------------------------
//Site Authentication
string userid;
string Name;
string strloginname;
string url = "http://" + System.Environment.MachineName + "/sites/" +
siteName;
SPSite siteCollection = new SPSite(url);
SPWeb site = siteCollection.OpenWeb();
site.AllowUnsafeUpdates = true;
SPUserCollection users = site.SiteUsers;
foreach (Microsoft.SharePoint.SPUser user in users)
{
if ((user.LoginName.ToString().ToUpper()) == (
System.Security.Principal.WindowsIdentity.GetCurrent().Name).ToUpper())
{
userid = user.ID.ToString();
strloginname = user.LoginName;
Name = user.Name;
goto exitForStatement0;
}
}
exitForStatement0: ;

-----------------------------------

 
Answer #2    Answered By: Bahadur Kotoky     Answered On: Jan 24

In a SharePoint context, like a Web Part, Application Page, or an
ASP.NET application embedded within a WSS context, you can use the
following C#:

SPUser currUser =
Microsoft.SharePoint.SPContext.Current.Web.CurrentUser;
string currLogin = currUser.LoginName;


Of course, if you don't have a SharePoint context, ASP.NET also knows
who is logged:
User currUser = System.Web.HttpContext.Current.User.Identity;
string currLogin = currUser.Name;


In a Content Editor Web Part just use:
<h1>_LogonUser_</h1>

 
Didn't find what you were looking for? Find more on User Account Look-Ups in SharePoint 2007 Or get search suggestion and latest updates.




Tagged: