Asp.net-Mvc
ASP.NET MVC - 針對 Active Directory 對使用者進行身份驗證,但需要輸入使用者名和密碼
我正在開發一個 MVC3 應用程序,該應用程序將要求使用者針對 AD 進行身份驗證。我知道 MVC3 中有一個選項可以創建一個 Intranet 應用程序,該應用程序自動針對 AD 對使用者進行身份驗證,但它使用 Windows 身份驗證並自動登錄。此應用程序可以在“開放”工作站上訪問,使用者需要輸入他們的域使用者名和密碼。任何範例或線上教程都會很棒。一個範例項目將是例外。
您可以將標準 Internet 應用程序模板與表單身份驗證一起使用,並將一個
ActiveDirectoryMembershipProvider插入到web.config:<connectionStrings> <add name="ADConnectionString" connectionString="LDAP://YOUR_AD_CONN_STRING" /> </connectionStrings> <system.web> <authentication mode="Forms"> <forms name=".ADAuthCookie" loginUrl="~/Account/LogOn" timeout="15" slidingExpiration="false" protection="All" /> </authentication> <membership defaultProvider="MY_ADMembershipProvider"> <providers> <clear /> <add name="MY_ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" /> </providers> </membership> </system.web>通過這種方式,您將獲得 Internet 應用程序模板登錄表單,並為您驗證 AD。
然後只需進行一些
AccountController清理即可刪除重置密碼/更改密碼/註冊功能,只留下登錄。