English 中文(简体)
How to restore an IIS Metabase backup using C#
原标题:

I ve found the Stack Overflow question describing how to backup the IIS Metabase in C# here, and I have been successful at getting that to work using the code referenced here. However, I am having difficulty restoring those backups (or indeed any backups created manually in IIS) using C# code.

Does anyone know how to do this, or even if it can be done? I haven t been able to find any examples of this on the web, unlike the backup itself.

I have tried the following code, but receive the error Exception has been thrown by the target of an invocation

using (DirectoryEntry localhostIIS = new DirectoryEntry("IIS://LocalHost"))
{
   localhostIIS.Invoke("Restore", new object[] { string.Empty, 0, 0});
}

Now while I m sure that I m calling the method with the wrong name and/or object structure, I haven t been able to find the correct way of calling it anywhere....

Can anybody please point me in the right direction?

最佳回答

I tried this with a named backup and got this to work with some tweaks:

const uint MD_BACKUP_HIGHEST_VERSION = 0xfffffffe;
const uint MD_BACKUP_NEXT_VERSION = 0xffffffff;
const uint MD_BACKUP_SAVE_FIRST = 2;

using(DirectoryEntry de = new DirectoryEntry("IIS://Localhost"))
{
  // Backup using the next version number (MD_BACKUP_NEXT_VERSION)
  de.Invoke("Backup", new object[] {
      "test-backup",
      MD_BACKUP_NEXT_VERSION,
      MD_BACKUP_SAVE_FIRST
  });

  // Restore the highest version number (or specify the specific version)
  de.Invoke("Restore", new object[] {
    "test-backup",
    MD_BACKUP_HIGHEST_VERSION,
    0
  });
}
问题回答

暂无回答




相关问题
Session Management with Windows Authentication

In an ASP.NET web app, using Integrated Windows Authentication, is the session tied to the windows identity? In other words, if I login (using IWA) to the app, and the app stores some "stuff" in my ...

Using Elmah with Cassini

Does anyone know if I can use Elmah with Visual Studio build-in web server(aka Cassini)? I get it working easily on IIS, but using same configuration, it doesn t work with Cassini. When I requested ...

Setting hostname in IIS, include www?

I want to set the hostname for a website I m adding in IIS 7, however do I include the www in the hostname or not? because I want both www.mysite.com and mysite.com both to point to mysite on the ...

inetpub versus any other folder

I ve run websites out of inetpub, as well as from folders just residing on the C: drive. I wonder, are there any definitive advantages to running websites out of inetputwwwroot?

IIS 6.0 hangs when serving a web-service

I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...

热门标签