以找到解决办法啦! 从写 System.Web.UI.Pageusing System;
using System.Web.UI;
/// <summary>
/// 所有 aspx 页面都继承此类
/// </summary>
public class BasePage : Page
{
public string ApplicationPath;
protected void Page_Load(object sender, EventArgs e)
{
ApplicationPath = Request.ApplicationPath;
if (ApplicationPath == "/")
{
ApplicationPath = "";
}
}
复制代码新建页面继承BasePage,并调用 base.Page_Load(sender, e) public partial class class_Default : BasePage { protected void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); Response.Write("0------------------"+ApplicationPath+"<br>"); } }
图象路径改为:<img src="<% = ApplicationPath %>/images/head/none.gif" /> 即可。 呵呵,同理所有 master 页面都继承System.Web.UI.MasterPagepublic class BaseMasterPage : MasterPage
{
public string ApplicationPath;
protected void Page_Load(object sender, EventArgs e)
{
ApplicationPath = Request.ApplicationPath;
if (ApplicationPath == "/")
{
ApplicationPath = "";
}
}
}
复制代码/// 所有 ascx 页面都继承此 System.Web.UI.UserControlpublic class BaseUserControl : UserControl
{
public string ApplicationPath;
protected void Page_Load(object sender, EventArgs e)
{
ApplicationPath = Request.ApplicationPath;
if (ApplicationPath == "/")
{
ApplicationPath = "";
}
}
}
复制代码