[英]How work with Active Directory in ASP.NET MVC
抱歉,我正在創建已經有答案的問題,但我不理解。
我需要一個簡單的應用程序,它將使用AD並使用用戶角色。
首先,我遇到了獲取連接字符串的問題。 給我一個用戶,並說它可以這樣連接:
LDAP://CN=User_1,OU=Test,OU=ADTestOU,DC=tv-tel,DC=local
放到web.config
什么?
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://CN=User_1,OU=Test,OU=ADTestOU,DC=tv-tel,DC=local" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!--Make sure you have fomrs authentication enabled.-->
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="MyADMembershipProvider">
<providers>
<add
name="MyADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionProtection="Secure"
connectionUsername="user"
connectionPassword="pwd"
attributeMapUsername="sAMAccountName"
enableSearchMethods="true"
attributeMapEmail="mail"
/>
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
</system.web>
如果要在AD中使用Windows身份驗證,則需要在web.config中使用<authentication mode="windows" />
而不是forms
。
嘗試使用Intranet應用程序模板創建一個新的ASP.NET MVC 3應用程序,它將為您進行設置。
另外,請確保已正確配置IIS並啟用了Windows身份驗證。 使用Intranet模板創建新項目時,它將為您生成一個文本文件,說明如何逐步設置它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.