I'm working on as asp.net application. The application is reasonably large and involves lot of pages with many reference images and scripts. I have hosted such content on a cookie-free sub-domain.
My problem is - I have to manually update the path for all images and scripts upon deployment, by making them absolute-references to cookie-free domain content from relative-references of actual domain. How do I automate this ? Has anybo开发者_Go百科dy done this ?
StackOverflow also uses cookie-free domain for various images on the site. Here's example upvote image which loaded from http://sstatic.net/so/img/vote-arrow-up.png
alt text http://sstatic.net/so/img/vote-arrow-up.png
I solved a similar problem with custom controls (Images, etc.). Some I derived from existing controls (Image) some I created new.
Within these Controls you could decide if you are in your dev environment or in production and render/change your links.
EDIT: Add some example code. Note! This code is for demonstration purpose only! It's not perfekt!
public class ExternalImage : System.Web.UI.WebControls.Image
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (System.Configuration.ConfigurationManager.AppSettings["IsDev"] != "true")
{
this.ImageUrl = System.Configuration.ConfigurationManager.AppSettings["CookieFreeDomain"] + this.ImageUrl;
}
}
}
You can use tag transforms or control adapters.
In case it helps, I cover both approaches in my book, along with code examples: Ultra-Fast ASP.NET
精彩评论