Obwohl dies kein gängiger Ansatz in ASP.NET ist, ist dies sehr wohl möglich, indem man ein Konstrukt namens VirtualPathProvider
für ASP.NET. Damit können Sie Website-Inhalte aus Dingen bereitstellen, die nicht das Dateisystem sind. So können Sie zum Beispiel eine ASP.NET-Website direkt aus einer ZIP-Datei bereitstellen, ohne die Dateien vorher auf der Festplatte zu entpacken.
Hier ist ein Download das das Konzept demonstriert oder veranschaulicht, indem es die DotNetZip-Bibliothek verwendet, um ASP.NET beim Herausziehen von Inhalten aus der Zip-Datei zu unterstützen.
Die interessanten Code-Bits:
using Ionic.Zip;
namespace Ionic.Zip.Web.VirtualPathProvider
{
public class ZipFileVirtualPathProvider : System.Web.Hosting.VirtualPathProvider
{
ZipFile _zipFile;
public ZipFileVirtualPathProvider (string zipFilename)
: base () {
_zipFile = ZipFile.Read(zipFilename);
}
~ZipFileVirtualPathProvider () {
_zipFile.Dispose ();
}
public override bool FileExists (string virtualPath)
{
string zipPath = Util.ConvertVirtualPathToZipPath (virtualPath, true);
ZipEntry zipEntry = _zipFile[zipPath];
if (zipEntry != null)
{
return !zipEntry.IsDirectory;
}
else
{
// Here you may want to return Previous.FileExists(virtualPath) instead of false
// if you want to give the previously registered provider a process to serve the file
return false;
}
}
public override bool DirectoryExists (string virtualDir)
{
string zipPath = Util.ConvertVirtualPathToZipPath (virtualDir, false);
ZipEntry zipEntry = _zipFile[zipPath];
if (zipEntry != null)
{
return zipEntry.IsDirectory;
}
else
{
// Here you may want to return Previous.DirectoryExists(virtualDir) instead of false
// if you want to give the previously registered provider a chance to process the directory
return false;
}
}
public override VirtualFile GetFile (string virtualPath) {
return new ZipVirtualFile (virtualPath, _zipFile);
}
public override VirtualDirectory GetDirectory (string virtualDir)
{
return new ZipVirtualDirectory (virtualDir, _zipFile);
}
public override string GetFileHash(string virtualPath, System.Collections.IEnumerable virtualPathDependencies)
{
return null;
}
public override System.Web.Caching.CacheDependency GetCacheDependency(String virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
{
return null;
}
}
}
Das VPP-Konstrukt funktioniert mit ASP.NET 2.0 oder höher, funktioniert mit jeder Website. Sie können die Idee natürlich anpassen, um Inhalte aus einer Datenbank, einem CMS oder ... zu beziehen.