2017-07-01 4 views
2

ユーザーがイントラネットアプリケーションにログインできるようにするには、Windows資格情報を使用する必要があります。私はユーザー名とロールを持つテーブルを作成し、Environment.UserNameのユーザー名と私のテーブルを比較する予定です。これを中継するのはどれくらい安全ですか?このタスクを達成するためのより良い方法はありますか?イントラネットアプリケーションでユーザーを認証する

ありがとうございます。

答えて

0

あなたは、この使用してActive Directory認証を行うことができます。

ベローは、あなたのアプリケーションで試すことができるサンプルコードです。あなたがWindowsアプリケーションで開発している場合

 string domainUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name; 
     string[] paramsLogin = domainUser.Split('\\'); 

     string domain = paramsLogin[0].ToString(); 
     string LdapPath = ""; 
     string strDomainPath = DomainPath(); 

     LdapPath = string.Format("LDAP://{0}/{1}", DomainName, strDomainPath); 

     string username = LoginUser.UserName; 
     string password = LoginUser.Password;   


     string domainAndUsername = domain + @"\" + username; 
     DirectoryEntry entry = new DirectoryEntry(LdapPath, domainAndUsername, password); 
     try 
     { 
      // Bind to the native AdsObject to force authentication. 
      Object obj = entry.NativeObject; 
      DirectorySearcher search = new DirectorySearcher(entry); 
      search.Filter = "(SAMAccountName=" + username + ")"; 
      search.PropertiesToLoad.Add("cn"); 
      SearchResult result = search.FindOne(); 
      if (result != null) 
      { 
       IsLoginSucess = true; 
       //Do your stuff here 
      } 

      // Update the new path to the user in the directory 
      LdapPath = result.Path; 
      string _filterAttribute = (String)result.Properties["cn"][0]; 
     } 
     catch (Exception ex) 
     { 
      IsLoginSucess = false;     
     } 
0

、これを見てみましょう:あなたは、Webアプリケーションを開発している場合

Authenticate user in WinForms (Nothing to do with ASP.Net) System.Security.Principal.WindowsIdentity.GetCurrent()はあなたの現在のWindowsユーザ

を与えるだろう、そこにあります組み込みのサポートでは、web.configファイルに関連するエントリが必要です。

Using windows authentication in asp.net with c#

HttpContext.Current.User.Identityあなたにユーザーの身元をお知らせします

関連する問題