我可以得到“WAR 文件"吗?使用 ASP.NET 类型部署? [英] Can I get "WAR file" type deployment with ASP.NET?

查看:20
本文介绍了我可以得到“WAR 文件"吗?使用 ASP.NET 类型部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Sometimes J2EE-savvy people look at ASP.NET and wonder, where's the support for deploying an app as a single unit? JSP/Servlet apps can be deployed as WAR files, with all pages, content, metadata, and code in that single archive. The war file can be versioned, easily moved around. There's an assurance that the entire app is contained in a single unit.

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

That's not a mainstream approach for ASP.NET. What do people do? Do they resort to copying directories and all the myriad files? Is this just not a problem for ASP.NET developers?

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

(this is sort of a cheat, because I'm going to suggest my own answer)

推荐答案

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

Although not a mainstream approach in ASP.NET, this is very possible, using a construct called the VirtualPathProvider for ASP.NET. With it, you can serve website content out of things that are not the filesystem. For one example, you could serve an ASP.NET website directly out of a ZIP file, without unzipping the files to disk, first.

这是演示或说明的下载概念,使用 DotNetZip 库来帮助 ASP.NET 从 zip 中提取内容.

Here's a download that demonstrates or illustrates the concept, using the DotNetZip library to assist ASP.NET in pulling content out of the 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 或... ??

The VPP construct works with ASP.NET 2.0 or later, works with any website. You can of course adapt the idea to source content from a database, a CMS, or ... ??

这篇关于我可以得到“WAR 文件"吗?使用 ASP.NET 类型部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆