Have a look at the HostingEnvironment class, especially the IsHosted method.
This will tell you if you are being hosted in an ApplicationManager, which will tell you if you are being hosted by ASP.NET.
Strictly, it will not tell you that you are running under IIS but I think this actually meets your needs better.
Example code:
// Returns the file-system path for a given path.
public static string GetMappedPath(string path)
{
if (HostingEnvironment.IsHosted)
{
if (!Path.IsPathRooted(path))
{
// We are about to call MapPath, so need to ensure that
// we do not pass an absolute path.
//
// We use HostingEnvironment.MapPath, rather than
// Server.MapPath, to allow this method to be used
// in application startup. Server.MapPath calls
// HostingEnvironment.MapPath internally.
return HostingEnvironment.MapPath(path);
}
else {
return path;
}
}
else
{
throw new ApplicationException (
"I'm not in an ASP.NET hosted environment :-(");
}
}