ASP.NET MVC: Displaying images for subdomains
I'm 开发者_如何转开发working on an multi tenant app, so I have a lot of dynamic subdomains:
user1.example.com user2.example.com
etc
It works great, but there's one problem though. Images are not displayed.
<img src="/images/logo.png" />
Will display on example.com, but it won't work on user1.example.com
I can of course use the following solution:
<img src="http://example.com/images/logo.png" />
But I want to have something more elegant if that's possible.
If the images are common, why don't you host them on a sperate subdomain such as static.example.com. This will help performance too as the images will be cached if people use applications on multiple subdomains. Putting other static content there, such as common javascript files, will aid performance too.
You can also create a custom HTML Helper to output the static URL for the image.
Have you tried using something like: <img src="<%=Url.Content("~/")%>images/logo.png" />
精彩评论