Reputation: 13820
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
, and Subsite2
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)?
Upvotes: 2
Views: 2484
Reputation: 4841
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.
Upvotes: 3
Reputation: 39306
One option is create resources.site.com which has the shared images or move it to a CDN.
Then, in each of the sites that consumes those resources, there is a configuration settings where the resources are. Those sites, format fully qualified urls to the resources using the config setting.
Since you've abstracted out resources.site.com in your code, it could be on the same server, different server, in a CDN etc... It doesn't matter - you're flexible how you serve them up. You could also start with it on the same server and when you want to optimize for geo, move it to a CDN.
Upvotes: 1
Reputation: 7765
you should create a cdn
subdomain and point the resources files to that e.g.
http://cdn.parentsite.com/images/logo.jpg
http://cdn.parentsite.com/css/site.css
etc..
This~/images/logo.jpg
will never resolve to anything other then the root of the app. That's the whole point of the ~
.
Upvotes: 3