ASP.NET 2.0提供的Web Resources管理模型,很好的解决了image、css、script等外部资源的管理问题在自定义控件中加入(放在最高级namespace外就行。) [assembly: WebResource("WebCtrl.cutecat.jpg", "image/jpg")] [assembly: WebResource("WebCtrl.cutecat.js", "application/x-javascript")] 代码:WebResource Demo#region WebResource Demo using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; [assembly: WebResource("WebCtrl.cutecat.jpg", "image/jpg")] namespace WebCtrl { [DefaultProperty("Text")] [ToolboxData("<{0}:WebCustom runat=server></{0}:WebCustom>")] public class WebCustom : WebControl { private string text; private Image m_Image; [Bindable(true)] [Category("Appearance")] [DefaultValue("")] public string Text { get { return text; } set { text = value; } } protected override void CreateChildControls() { m_Image = new Image(); this.Controls.Add(m_Image); } protected override void Render(HtmlTextWriter output) { m_Image.ImageUrl = this.Page.GetWebResourceUrl(typeof(WebCustom), "WebCtrl.cutecat.jpg"); this.RenderChildren(output); } } } #endregion 转载于:https://www.cnblogs.com/goldnet/archive/2008/02/22/1077895.html