.net - 我可以使用 ASP.NET 获得 "WAR file"类型的部署吗?

标签 .net asp.net deployment archive

有时,精通 J2EE 的人看着 ASP.NET 并想知道,将应用程序部署为单个单元的支持在哪里? JSP/Servlet 应用程序可以部署为 WAR 文件,所有页面、内容、元数据和代码都在单个存档中。 war 文件可以进行版本控制,很容易移动。可以保证整个应用程序都包含在一个单元中。

这不是 ASP.NET 的主流方法。人们做什么?他们是否诉诸复制目录和所有无数文件?这对 ASP.NET 开发人员来说不是问题吗?

(这有点像作弊,因为我将建议我自己的答案)

最佳答案

尽管这不是 ASP.NET 中的主流方法,但使用名为 VirtualPathProvider 的构造很有可能实现。对于 ASP.NET。有了它,您可以从不是文件系统的东西中提供网站内容。例如,您可以直接从 ZIP 文件中提供 ASP.NET 网站,而无需先将文件解压缩到磁盘。

Here's a download演示或说明该概念,使用 DotNetZip 库帮助 ASP.NET 从 zip 中提取内容。

有趣的代码位:

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;
        }
    }
}

VPP 构造适用于 ASP.NET 2.0 或更高版本,适用于任何网站。您当然可以调整想法以从数据库、CMS 或 ... ??

关于.net - 我可以使用 ASP.NET 获得 "WAR file"类型的部署吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/619704/

相关文章:

c# - 从 C# DLL 动态获取代码

c# - 请求中对象的值在wcf服务中始终为null

c# - 如何在 ASP-NET C# 中从特定路径打开文件?

c# - 为什么 Visual Studio 在选择设备时尝试部署到模拟器

java - 为什么我的 Tomcat 7 在部署后停止工作

.net - 基于 XSD 数据集创建 SQLite 数据库

c# - 在protobuf-net中,[ProtoContract(ImplicitFields = ImplicitFields.AllFields)]的等价代码是什么?

c# - 正确地将 C++ long 转换为 C# int

asp.net - 为什么我的 UpdatePanel 不会像我期望的那样在单击按钮时更新我的​​列表框?

linux - 在 Linux 上托管的 Sonatype Nexus 存储库上部署 Maven Artifact