获取MOSS当前登录用户信息

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using Microsoft.Office.Server;
namespace 获得当前用户
{
   
public partial class GetEmployee : System.Web.UI.UserControl
    {
       
protected void Page_Load(object sender, EventArgs e)
        {
            SPSite spSite
= new SPSite("moss的站点地址");

            SPWeb web
= spSite.RootWeb;
           
string userName = web.CurrentUser.Name;

            txtEmployee.Value
= userName;
        }
    }
}

web.currentuser   这个有很多当前用户的属性   想要显示那个就用那个属性

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Security.Principal;

namespace Test
{
   
public class DomainUser : WebPart
    {
       
protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
           
//获取当前登陆用户的登陆名  
            WindowsPrincipal wp = (WindowsPrincipal)System.Threading.Thread.CurrentPrincipal;
           
string wpname = wp.Identity.Name.ToString();
           
int j = wpname.LastIndexOf("\\");
           
string userName = wpname.Substring(j + 1);
           
string domainName = wpname.Substring(0, j);
            writer.Write(domainName.ToString()
+ " \\ " + userName.ToString());
        }
    }
}


string strUserName = this.Page.User.Identity.Name;

posted @ 2008-05-26 14:54  ChoiceShan  阅读(418)  评论(0编辑  收藏  举报