如何解决不同网站的绝对URL在同一个父IIS虚拟目录的.NET? [英] How do I resolve absolute URLs for different sites in the same parent IIS virtual directory in .NET?
问题描述
我的目标是在多个网站都在IIS中的同一个父虚拟目录下托管共享图像,CSS,JS等。当然,我可以硬code图像的路径,但我希望有.NET,可以使用IIS配置智能解析URL的方法。
下面是我的文件/虚拟目录结构:
父站点(虚拟目录)
Default.aspx的
mypage.aspx
otherpage.aspx
图片
- logo.jpg
CSS
- 的site.css
subsite1的(虚拟目录)
- Default.aspx的
- products.aspx
Subsite2(虚拟目录)
- Default.aspx的
- products.aspx
- miscellaneous.aspx
块引用>
父网站
,subsite1的
和Subsite2
是所有虚拟目录设置了 http://parentsite.com ,的 http://subsite1.com 和 http://subsite2.com ,分别。我想在这些网站上分享图片,JS,CSS等。有没有在.NET中的方法将解决
〜/图像/ logo.jpg
为 http://parentsite.com/images/logo.jpg 从子网站之一(例如,的 http://subsite.com/default.aspx )?解决方案在IIS6甚至IIS7,您可以使用一个新的虚拟目录,称之为资产,在所有的儿童网站。
更新后的网站布局:
父站点(虚拟目录)
Default.aspx的
mypage.aspx
otherpage.aspx
资产
-images
- logo.jpg
-css
- 的site.csssubsite1的(虚拟目录)
- Default.aspx的
- products.aspx
资产(虚拟目录母公司资产)Subsite2(虚拟目录)
- Default.aspx的
- products.aspx
- miscellaneous.aspx
资产(虚拟目录母公司资产)通过这种结构,你可以分享所有站点相同的资产文件夹,仍可以访问它作为〜/资产。这使您可以与任何IIS正在回答的站点上使用的资产。
一个CDN是一个不错的选择,但是很多时候,你会为每个站点如 HTTP创建单独的DNS enteries://cdn.parentsite .COM 和 http://cdn.childsite.com 然后创建一些功能来引用文件作为的http:// CDN(currentdomain )
在我看来,使用到共享文件夹资产的绝对或相对路径将使生活变得更容易。
My goal is to share images, css, js, etc. across multiple websites that are all hosted under the same parent virtual directory in IIS. Of course, I could hard code the images paths, but I'd hoped .NET had a method that could intelligently resolve URLs using the IIS configuration.
Here is my file/virtual directory structure:
Parent Site (Virtual Directory) default.aspx mypage.aspx otherpage.aspx images - logo.jpg css - site.css Subsite1 (Virtual Directory) - default.aspx - products.aspx Subsite2 (Virtual Directory) - default.aspx - products.aspx - miscellaneous.aspx
Parent Site
,Subsite1
, andSubsite2
are all virtual directories set up for http://parentsite.com, http://subsite1.com, and http://subsite2.com, respectively. I want to share images, js, css, etc. across these sites.Is there a method in .NET that will resolve
~/images/logo.jpg
as http://parentsite.com/images/logo.jpg when called from one of the subsites (e.g., http://subsite.com/default.aspx)?解决方案In IIS6 and even IIS7 you can use a new virtual directory, call it "assets", in all of the children sites.
Updated site layout:
Parent Site (Virtual Directory) default.aspx mypage.aspx otherpage.aspx assets -images - logo.jpg -css - site.css Subsite1 (Virtual Directory) - default.aspx - products.aspx assets (Virtual Directory to parent assets) Subsite2 (Virtual Directory) - default.aspx - products.aspx - miscellaneous.aspx assets (Virtual Directory to parent assets)
With this structure you can share the same "assets" folder with all sites and still access it as "~/assets". This allows you to use the assets with any of the domains that IIS is answering for.
A CDN is a good option but often times you would create seperate DNS enteries for each site like http://cdn.parentsite.com and http://cdn.childsite.com and then create some function to reference the files as http://cdn.(currentdomain).
In my opinion, using an absolute or relative path to the shared assets folder will make life easier for you.
这篇关于如何解决不同网站的绝对URL在同一个父IIS虚拟目录的.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!