我能" WAR文件"键入与ASP.NET部署? [英] Can I get "WAR file" type deployment with ASP.NET?

查看:134
本文介绍了我能" WAR文件"键入与ASP.NET部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时J2EE精明的人看ASP.NET和惊奇,的在哪里部署应用程序作为一个单元的支持? JSP / Servlet的应用程序可以部署为WAR文件,所有的页面,内容,元数据和code。在单一存档。战争文件可以进行版本控制,容易感动身边。还有,整个程序被包含在一个单个单元的保证。

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。有了它,你可以为网站内​​容出来的东西不属于文件系统。对于一个例子,你可以直接服务于一个ASP.NET网站出一个ZIP文件,无需解压的文件到硬盘,第一。

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拉动含量超出了拉链。

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.

有趣code位:

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天全站免登陆