2014-12-05 43 views

回答

0

我的建議是建立基於AD羣的認證。

您可以創建一個或多個AD羣組並將您想要的用戶添加到該羣組。然後,您可以將對您的Web應用程序的訪問權限僅限於這些組。

然後在MVC中,您可以在您的Actions,Controllers上使用Authorize屬性,或將其設置爲全局過濾器。

基本用法

[Authorize([email protected]"MyCompanyDomain\\company-group-name-here")] 
+0

謝謝爲你的答案。這裏的問題:解決方案應該接受沒有固定定義的任何域。 – Simon 2015-03-13 10:49:36

0

我發現通過我MVC4 C#代碼的解決方案:

public static bool IsLocalUser(WindowsIdentity pIdentity) 
{ 
    // establish domain context   
    PrincipalContext lMachineContext = new PrincipalContext(ContextType.Machine); 

    // find user 
    UserPrincipal lMachineUser = UserPrincipal.FindByIdentity(lMachineContext, pIdentity.Name); 

    return lMachineUser != null; 
} 

在我的控制器,調用該方法,並通過身份:

if(IsLocalUser(HttpContext.User.Identity as WindowsIdentity)) 
{ 
    // block and refer to error site. 
} 
相關問題