【发布时间】:2013-01-15 10:29:33
【问题描述】:
我正在尝试在 ASP.net 应用程序中使用 AD 轻量级目录服务进行用户身份验证,并且不想使用表单身份验证。有没有办法使用windows身份验证来验证它。
<authentication mode="Windows" />
【问题讨论】:
我正在尝试在 ASP.net 应用程序中使用 AD 轻量级目录服务进行用户身份验证,并且不想使用表单身份验证。有没有办法使用windows身份验证来验证它。
<authentication mode="Windows" />
【问题讨论】:
你可以试试这个
How To: Use Windows Authentication in ASP.NET 2.0
How To: Use Forms Authentication with Active Directory in ASP.NET 2.0
编辑: 这对我有用:
<!-- web.config -->
...
<system.web>
...
<compilation debug="true">
<assemblies>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
<authentication mode="Windows"/>
<identity impersonate="true"/>
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
...
然后在代码中
//page.cs
...
string userName = HttpContext.Current.User.Identity.Name;
...
您应该能够使用例如DirectoryEntry Class 编写一些自定义代码,例如Enumerating Users and Groups。在这里您可以找到有关Using Active Directory Lightweight Directory Services 的更多信息。
【讨论】: