我正在 Intranet 上建立一个网站,其中一个目录只能由硬编码的授权用户访问。它们在 web.config 中定义。它看起来与此类似。
<location path="admin">
<system.web>
<authorization>
<allow users="user1"/>
<allow users="user2"/>
<allow users="user3"/>
<allow users="user4"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
然后我想要的是创建一个指向该目录的链接,该链接只显示给那些用户......目前,为了建立链接,我正在重新检查 Windows 用户名并像这样再次硬编码它们......
<%
if (HttpContext.Current.User.Identity.Name == "user1" ||
HttpContext.Current.User.Identity.Name == "user2" ||
HttpContext.Current.User.Identity.Name == "user3" ||
HttpContext.Current.User.Identity.Name == "user4")
{
Response.Write("<a href='admin/Default.aspx'>Admin Site</a>");
}
%>
但我想做的是从 webiconfig 文件中引用我的列表并说类似
if (HttpContext.Current.User.Identity.Name == // a user from the web.config list
这可能吗,如果可以的话,你能帮我...谢谢