2011-11-09 90 views
2

我有一個運行在IIS上的Web服務。 我的目標是能夠訪問密碼保護的Linux機器(Samba服務器)上的網絡文件夾。我可以在IIS上創建用戶帳戶,該帳戶將具有用戶名和密碼註冊,並且此帳戶將成爲asp.net用來運行該服務的帳戶。另外,我將從Linux機器上完全訪問此帳戶。有沒有辦法在IIS上註冊用戶名和密碼?

我的問題是,如果有可能將密碼傳遞給IIS元數據庫。

回答

1

通常我會在模擬代碼中執行此操作。你可以在一個易於使用的方式使用this small helper class

using (new Impersonator("myUsername", "myDomainname", "myPassword")) 
{ 
    // <code that executes under the new context> 
} 

另外,也有ASP.NET Impersonation可用。

+1

感謝幫助了很多 – apomene

1

How TO: Change Application Pool Identity Programmatically

//Initialize the metabase path 
    string metabasePath = "IIS://localhost/W3SVC/AppPools"; 
    //Specify the name for your application pool 
    string appPoolName = "testAppPool"; //specify the domain account as domain\username 
    //Specify the identity that will run the application pool 
    string appPoolUser = "User1"; 
    //Specify the password for the user 
    string appPoolPass = "Password1"; 
    DirectoryEntry pool1; 
    DirectoryEntry apppools = new DirectoryEntry(metabasePath); 
    pool1 = apppools.Children.Find(appPoolName, "IIsApplicationPool"); 

    /*Change Application Pool Identity*/ 
    pool1.InvokeSet("AppPoolIdentityType", new Object[] { 3 }); 
    pool1.InvokeSet("WAMUserName", new Object[] { Environment.MachineName + @"\" + appPoolUser }); //If you are using a local account 

    pool1.InvokeSet("WAMUserPass", new Object[] { appPoolPass }); 
    /*Commit changes*/ 

    pool1.CommitChanges(); 
+0

謝謝你的回答......真是幫了我 – apomene

+0

具有低代表投了 – apomene

+0

您仍然可以將其標記爲正確的。 –

相關問題