简体   繁体   English

用于通用标记的ASP.NET虚拟目录

[英]ASP.NET Virtual Directory For Common Markup

I have a few applications that need to share a common set of markup. 我有一些应用程序需要共享一组共同的标记。

Scenario: I might have www.site1.com, www.site2.com, and www.site3.com. 场景:我可能有www.site1.com,www.site2.com和www.site3.com。 On all sites, /care/contact-us.aspx and /care/faqs.aspx will be exactly the same, but every other page will be totally different. 在所有网站上,/ care / contact-us.aspx和/care/faqs.aspx将完全相同,但每隔一页都会完全不同。

Issue: I'm attempting to not duplicate the .aspx files for each of these sites and would like to have a /care virtual directory that would include contact-us.aspx and faqs.aspx that each of these sites would use. 问题:我试图不复制每个站点的.aspx文件,并希望有一个/ care虚拟目录,其中包含每个站点都会使用的contact-us.aspx和faqs.aspx。 I have seen this post from Scott Gu , but I'm looking for any other solutions/ideas. 我看过Scott Gu的这篇文章 ,但我正在寻找其他任何解决方案/想法。

Question 1: What would be the best way to set this up to share the /care directory? 问题1:将此设置为共享/ care目录的最佳方法是什么? Question 2: Any ideas about also sharing the code behind. 问题2:关于也分享背后代码的任何想法。

Background, if you care: In a legacy application (asp classic/vbscript), we have the ability to use a /common virtual directory for sites to share common markup and code (since they're all mixed together in .asp files). 背景,如果你关心:在遗留应用程序(asp classic / vbscript)中,我们能够使用/ common虚拟目录来共享站点共同的标记和代码(因为它们在.asp文件中混合在一起)。

Thanks in advance to any help or ideas! 在此先感谢任何帮助或想法!

Simply setup a virtual directory in IIS for each of the apps that points to the same physical directory. 只需在IIS中为每个指向同一物理目录的应用程序设置虚拟目录。

Here's a good reference: 这是一个很好的参考:

http://support.microsoft.com/kb/324785 http://support.microsoft.com/kb/324785

This is actually pretty hard, and i'd recommend you either bite the bullet and go with the scott gu answer or use the solution we chose, which was to use the svn:externals property within subversion to import a directory from a "shared" repository. 这实际上非常难,我建议你咬紧牙关并使用scott gu的答案或使用我们选择的解决方案,这是使用subversion中的svn:externals属性从“共享”导入目录库。 Subversion manual reference . Subversion手动参考 If you use a different version control system i would guess it would have something similar but you're on your own in that case. 如果您使用不同的版本控制系统,我猜它会有类似的东西,但在这种情况下你自己就是这样。

I use a virtual directory in order to share HTML and Image files between sites. 我使用虚拟目录,以便在站点之间共享HTML和图像文件。 To share ASPX files, things are a bit different - and harder. 要共享ASPX文件,事情会有所不同 - 而且更难。

When we share HTML files, we do not just link to that file because it would screw up the menu (different sites have different menus - we just want the content of the HTML files). 当我们共享HTML文件时,我们只是链接到该文件,因为它会搞砸菜单(不同的网站有不同的菜单 - 我们只想要HTML文件的内容 )。 So I created a page (eg "ShowContent.aspx") that opens up the HTML file, reads the contents as a string and assigns the string to an ASP label control. 所以我创建了一个页面(例如“ShowContent.aspx”),它打开HTML文件,将内容作为字符串读取,并将字符串分配给ASP标签控件。 This may work for you as-is if you don't generate the content dynamically in your shared ASPX files. 如果您不在共享ASPX文件中动态生成内容,这可能会对您有效。

Even if you do, hope is not lost. 即使你这样做,也不会失去希望。 First, create a project that incorporates JUST the common ASPX files, build it and place the project files in a known location ( http://shared.yoururl.com ). 首先,创建一个项目,其中包含常见的ASPX文件,构建它并将项目文件放在已知位置( http://shared.yoururl.com )。 Now, instead of pulling the contents by accessing a file, simply read the contents off using a WebRequest object: 现在,不是通过访问文件来拉取内容,而只需使用WebRequest对象读取内容:

        WebRequest wrContent = WebRequest.Create("http://shared.yoururl.com/CommonInformation.aspx");
        Stream objStream = wrContent.GetResponse().GetResponseStream();
        StreamReader objStreamReader = new StreamReader(objStream);
        string pageContent = objStreamReader.ReadToEnd();

Then display the pageContent on your blank page. 然后在空白页面上显示pageContent。

If your common pages are data entry forms then I'm afraid your only hope is to place them in a common source directory that multiple projects share. 如果您的常用页面是数据输入表单,那么我担心您唯一的希望是将它们放在多个项目共享的公共源目录中。 You'd share the source but would publish the files with each project. 您将共享源,但会发布每个项目的文件。 This is likely to be messy though: you may make changes in one that break other projects because they now have the possibility of interdependency. 这可能很麻烦:你可能会在打破其他项目的过程中进行更改,因为它们现在可能存在相互依赖性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM