i'm trying to add an application to site via code (C#) and i get a null reference. someone have an idea why?
here's the code i use: Application app;
using (var sm = new ServerManager())
{
if (site.Applications["/" + appName] == null)
{
site.Applications.Add("/" + appName, physicalPath);
sm.CommitChanges();
}
app = site.Applications["/" + appName];
}
return app;
the code fails on the "add" line. the appName is a string like "MyNewApp". the physicalPath is a string like "C:\\inetpub\\wwwroot\\MyService". the site is Microsoft.Web.Administration.Site object of the IIS6.1 (win 7 ent) default web site.
found the answer: NullReferenceException in Microsoft.Web.Administration when adding https binding
its all because of the "using" statement. the site didn't have a parent ServerManager at the point of the application add.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.