myuser.aspx.cs

来自「《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含」· CS 代码 · 共 37 行

CS
37
字号
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.VisualBasic.ApplicationServices;

public partial class MyUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		//读取用户信息
		Microsoft.VisualBasic.ApplicationServices.User user = new User();
		user.InitializeWithWindowsUser();
		int pos = user.Name.IndexOf("\\");
		Response.Write("用户姓名:" + user.Name.Substring(pos + 1, user.Name.Length - pos - 1) + "<BR/>");
		Response.Write("CurrentPrincipal:" + user.CurrentPrincipal + "<BR/>");
		Response.Write("是否经过验证:" + user.IsAuthenticated + "<BR/>");
		Response.Write("是否属于Administrator角色:" + user.IsInRole(BuiltInRole.Administrator) + "<BR/>");

		///*您也可以使用下列方式
		Response.Write("User Domain Name:" + System.Environment.UserDomainName + "<BR/>");
		Response.Write("User Name:" + System.Environment.UserName + "<BR/>");

		Response.Write("AuthenticationType:" + User.Identity.AuthenticationType + "<BR/>");
		Response.Write("IsAuthenticated:" + User.Identity.IsAuthenticated + "<BR/>");
		Response.Write("Name:" + User.Identity.Name + "<BR/>");
		Response.Write("IsInRole:" + User.IsInRole("Administrator") + "<BR/>");
		 //* */
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?