C# “如何改变”;LogonUserIdentity.Name“;用于调试

C# “如何改变”;LogonUserIdentity.Name“;用于调试,c#,asp.net,C#,Asp.net,出于调试目的,是否可以设置或更改System.Web.HttpContext.Current.Request.LogonUserIdentity.Name?我尝试更改它,但它是只读的: 错误10无法将属性或索引器“System.Security.Principal.WindowsIdentity.Name”分配给--它是只读的 我试图证明用户是否是特定active directory组的成员,以便从导航菜单中删除项目。因此,我必须检查用户组,我可以更改HttpContext.Current.us

出于调试目的,是否可以设置或更改
System.Web.HttpContext.Current.Request.LogonUserIdentity.Name
?我尝试更改它,但它是只读的:

错误10无法将属性或索引器“System.Security.Principal.WindowsIdentity.Name”分配给--它是只读的

我试图证明用户是否是特定active directory组的成员,以便从导航菜单中删除项目。因此,我必须检查用户组,我可以更改
HttpContext.Current.user.Identity.Name
进行调试,但使用
System.Web.HttpContext.Current.Request.LogonUserIdentity.Name
我正在读取组:

List<string> groups = new List<string>();
foreach (System.Security.Principal.IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
            groups.Add(group.Translate(typeof(System.Security.Principal.NTAccount)).ToString());
列表组=新列表();
foreach(System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups中的System.Security.Principal.IdentityReference组)
Add(group.Translate(typeof(System.Security.Principal.NTAccount)).ToString();

谢谢

也许多了解一些情况会有帮助。你想做什么?@CelestialDragonofOsiris:请看我的editWell,因为属性是
readonly
,你不能更改它,但是你可以先将值赋给一个局部变量,然后使用它,而不是直接使用属性,这样你就可以编辑它进行调试,当你需要的时候。也许多了解一些情况会有帮助。你想做什么?@CelestialDragonofOsiris:请看我的editWell,因为属性是
只读的
,你不能更改它,但是你可以先将值赋给一个局部变量,然后使用它,而不是直接使用属性,这样,你可以在需要时编辑它进行调试。