Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Get curently logged in user

  Asked By: Dontae    Date: Aug 17    Category: Sharepoint    Views: 2045

I want to create a webpart which displays the currently logged in user.
Do we have any existing webpart which does this or do i need to write a
custom webpart. Any pointers on how do we go abt creating this webpart
will be very helpful.



3 Answers Found

Answer #1    Answered By: M Juarez     Answered On: Aug 17

Many ways to do that.
try this for now :

SPWeb spWeb = SPControl.GetContextWeb(System.Web.HttpContext.Current);
string user  = spWeb.CurrentUser.Name.ToString();

Answer #2    Answered By: Marty Mcdowell     Answered On: Aug 17

Somebody else idea : save this as username.aspx in
%Drive%:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033

and then run as

<%@ Page language="C#"%> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace=" Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<% SPSite spServer = SPControl.GetContextSite (System.Web.HttpContext.Current); SPWeb spWeb = SPControl.GetContextWeb(System.Web.HttpContext.Current); %>

spServer.CatchAccessDeniedException = false;

string welcome = "Welcome to the " + spWeb.Title + " site. ";
string welcome2 = "You are logged  on as: " + spWeb.CurrentUser.Name ;
catch(System.UnauthorizedAccessException ex)

<BODY height=40px scroll="no">
<TABLE ><TR><td style="font-family:Arial; font-size:10pt; font-weight:bold; color:#af0b1c"><%=welcome%> </td></TR>
<TR><td style="font-family:Arial; font-size:10pt; font-weight:bold; color:#000000"><%=welcome2%> </td></TR></TABLE>

Answer #3    Answered By: Ted Gilmore     Answered On: Aug 17

Here is a ready web part sharepoint.advis.ch/.../Default.aspx

Didn't find what you were looking for? Find more on Get curently logged in user Or get search suggestion and latest updates.