Well, I think I answered my own questions. Here's the test code that I put in my custom control. In order for the MapPath one to work on virtual folders that you created in IIS you need to open your project using
http://localhost/myproject, and not use the file system method. This code was tough to figure out. I hope it helps someone.
private String MapPath(string name)
{
if (Page != null && Page.Site != null && Page.Site.DesignMode)
{
IWebApplication app = (IWebApplication)Page.Site.GetService(typeof(IWebApplication));
if (app != null)
{
IProjectItem pItem = app.GetProjectItemFromUrl(name);
if (pItem != null)
{
return pItem.PhysicalPath;
}
else
{
return "URL not found in project";
}
}
return "Can not get IWebApplication at DesignTime";
}
else if (Page != null)//Runtime
{
return Page.MapPath(name);
}
else
{
return "No page to map path from";
}
}
private String GetAppSetting(string name)
{
if (Page != null && Page.Site != null && Page.Site.DesignMode)
{
IWebApplication app = (IWebApplication)Page.Site.GetService(typeof(IWebApplication));
if (app != null)
{
Configuration config = app.OpenWebConfiguration(true);
if (config != null)
{
return config.AppSettings.Settings[name].Value;
}
}
return "Can not get AppSettings at DesignTime";
}
else //Runtime
{
return WebConfigurationManager.AppSettings[name];
}
}