开发者

add domain to images source at runtime

I have a number of images on my 开发者_如何学Gowebsite (asp.net c# web.application) that are loaded on to my site. I have a specific domain that I use to load images with but I dont have it included in my markup. So at runtime I want to add this domain to the images if they dont already have it added at compile time. Whats the best way of doing this? Is it via a http module? I understand by doing this at runtime will have performance issues so if there are any other ways I am open to suggestions. Most of my images have relative paths. I cant hard code the domain as it changes by environment the application is running in.


Put the domain in your web.config's app settings, then at the top of the web form or master page, do:

<% string ImagesDomain = System.Configuration.ConfigurationSettings.AppSettings["ImagesDomain"] %>

Then in your images, do:

<img src="<%=ImagesDomain%>/MyImage.jpg" />

Simple enough. Don't worry too much about the performance hit either, it'll be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜