2013-06-25 107 views
0

在我的web應用程序中,我有一個login.aspx頁面。當我輸入用戶名和密碼時,我需要在遠程服務器上驗證它。他們只給我提供服務器名稱(路徑)和域名(不知道密碼和用戶名)。如何做呢?asp.net中C#中的LDAP身份驗證

我的web.config

<authentication mode="Forms"> 
    <forms loginUrl="Login.aspx" timeout="10"/> 
    </authentication> 

我已閱讀LDAP Authentication in ASP.Net MVC 但是,在會員供應商,他們的連接,密碼和用戶名寫道。

我該怎麼辦?

回答

1

像答案有說:

連接保護,用戶名和pwd是可以訪問查詢代系統的AD帳戶。根據網絡的安全性,這可能需要設置,否則您將無法查詢AD以驗證用戶身份。

它取決於您應該如何進行身份驗證的服務器配置。

1

如果您只需要驗證用戶是否存在並且密碼有效,則可以使用如下所示:參數爲域名,用戶標識和用戶密碼。由於我們沒有查詢任何內容,因此非管理員權限即可。

public static bool LogonValid(string ldapDomain, string userName, string password) { 
    DirectoryEntry de = new DirectoryEntry(@"LDAP://" + ldapDomain, userName, password); 

    try { 
    object o = de.NativeObject; 
    return true; 
    } 
    catch (Exception ex) { 
    logger.Error(ex.ToString()); 
    return false; 
    } 
} 

可能有這樣的原因,在任何情況下都不起作用,但目前爲止還是有效的。

+0

thankyou..but遠程運行時顯示錯誤:「請求類型'System.DirectoryServices.DirectoryServicesPermission,System.DirectoryServices,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'的權限失敗。」你能幫我嗎 ? @Brad Bruce – ARATHY

+0

我的應用程序以完全信任的方式運行。這聽起來像你正在運行一個較低的信任級別。這裏有一篇文章描述了一種只添加所需權限的方法。 http://ammarfassy.wordpress.com/2012/07/10/system-security-securityexception-request-for-the-permission-of-type/ –