2013-07-01 48 views
2

我是mvc3和i的初學者,我創建了一個Internet應用程序,爲此我需要應用Windows身份驗證並檢查AD中的用戶角色。這可能與LDAP?我在網上搜索,但似乎沒有清楚。因此,要求你們協助或發佈一些鏈接,對於要遵循的程序有明確的解釋。在mvc3中通過LDAP進行Windows身份驗證

在此先感謝!

+0

可能是一個問題http://serverfault.com – mishik

回答

0

這是可能的,

看一看這個URL

0

是的,它是可能的。網上有很多樣本。

在你的web.config添加LDAP連接字符串:

<connectionStrings> 
    <add name="ADConnectionString" connectionString="LDAP://what ever it is" /> 
</connectionStrings> 

還增加以下內容:

<authentication mode="Forms"> 
    <forms name=".ADAuthCookie" loginUrl="~/Account/LogOn" timeout="15" slidingExpiration="false" protection="All" /> 
</authentication> 

<membership defaultProvider="ADMembershipProvider"> 
    <providers> 
      <clear /> 
      <add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" /> 
    </providers> 
</membership> 

其餘的應該工作一樣正常SQL成員:

public ActionResult LogOn() 
{ 
    return View(); 
} 

[HttpPost] 
public ActionResult LogOn(LogOnViewModel viewModel, string returnUrl) 
{ 
    if (ModelState.IsValid) 
    { 
      if (Membership.ValidateUser(viewModel.UserName, viewModel.Password)) 
      { 
      } 
    } 
} 

Your LogOnViewModel: 

public class LogOnViewModel 
{ 
    public string UserName { get; set; } 

    public string Password { get; set; } 
} 

我希望這可以幫助你在正確的方向。

相關問題