有没有办法在IIS上注册帐户的用户和密码?

时间:2011-11-09 13:51:56

标签: asp.net web-services

我在IIS上运行了一个Web服务。 我的目标是能够访问受密码保护的Linux机器(Samba服务器)上的网络文件夹。我可以在IIS上创建一个用户帐户,该帐户将具有用户名和密码注册,该帐户将是asp.net用于运行服务的帐户。此外,我将从Linux计算机上完全访问此帐户。

我的问题是,如果可以将密码传递给IIS元数据库。

2 个答案:

答案 0 :(得分:1)

通常我会在代码中进行模拟。您可以以易于使用的方式使用this small helper class

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

或者,也有ASP.NET Impersonation可用。

答案 1 :(得分: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();