我正在运行一个需要能够读取当前用户的登录ID的网页.这是我正在使用的代码:
string id = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Run Code Online (Sandbox Code Playgroud)
目前,这将返回正确的登录,但是当我在此方法中使用它时:
protected Boolean isPageOwner()
{
string id = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
alert("User: " + id);
if (id.Equals(pageOwnerID))
{
return true;
}
if (accessPermission.ContainsKey(id))
{
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
即使返回的id与pageOwnerID相同,该方法也返回false.我真的不确定我遇到问题的哪一部分.
另外,我的登录ID的格式为string1/string2,但代码将其检索为string1 + string2而不使用斜杠.
任何建议表示赞赏.
问候.
Sli*_*SFT 10
尝试使用它来检索用户名....
if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
string username = System.Web.HttpContext.Current.User.Identity.Name;
}
Run Code Online (Sandbox Code Playgroud)
听起来好像没有使用Windows身份验证 - 您需要禁用匿名访问并启用Windows集成安全性.
将其添加到您的web.config中......
<system.web>
<authentication mode="Windows"/>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23000 次 |
| 最近记录: |