我也認爲,在辦公用戶使用主動目錄和支持非辦公用戶以及一個WinForms桌面應用程序。
這可能不止是你的要求,但因爲我有和你一樣的場景,所以我會提供它,因爲它以一種很好的方式聚集在一起,我真的沒有寫得太多代碼並一直運行良好。
我相信其他人可能已經做到了這一點與相對於自己捲包 - 和說實話,我可能會去下一次我有這樣的要求,這條路......
這:
概念我參加了一個線索,從ASP.NET並打破安全爲兩個邏輯部分:
認證 - 這是誰的用戶?
授權 - 用戶可以這樣做嗎?
我實現使用一個簡單的數據庫:
下面是從我的應用程序的主要形式snippett:
public EOMForm()
{
InitializeComponent();
// Show the connection string when hovering over the database label (Test Mode Only)
if(Properties.Settings.Default.TestMode)
this.toolTip1.SetToolTip(this.databaseLabel, EomAppCommon.EomAppSettings.ConnStr);
// Security
DisableMenus();
}
private void DisableMenus()
{
// Disable individual menu items
foreach (var menuItem in this.TaggedToolStripMenuItems())
menuItem.Enabled = Security.User.Current.CanDoMenuItem((string)menuItem.Tag);
// Apply disabled color to top level menus that have all their items disabled
foreach (var menu in menuStrip1.DisabledMenus())
menu.ForeColor = SystemColors.GrayText;
}
而且here's the supporting utility code。
最後,我用一個ASP.NET網站支架對其進行管理:
非常感謝您對放棄這麼多的代碼,但是,如你所說,這比多路我在問,而且我迷失在你的代碼中尋找我想要的東西:一種方法來知道用戶是否已在Active Directory中進行身份驗證。它在WindowsIdentityHelper類中嗎? –
我可能會拆分反斜槓返回的字符串,並將第一個元素與我公司的已知域名進行比較。因此,在辦公室他們的身份是mycompany \ joe,在家裏他們的身份是joescomputer \ joey –
我添加了WindowsIdentityHelper以防萬一它幫助你 - 那裏可能有幫助的是檢查組的例程,如果有隻有你的辦公室用戶纔會有... –