ASP.NET:合并URL重写、ASP:ImageButton和html基本标记时图像被破坏

ASP.NET:合并URL重写、ASP:ImageButton和html基本标记时图像被破坏,asp.net,asp.net-4.0,url-rewriting,Asp.net,Asp.net 4.0,Url Rewriting,我在ASP.NET 4下使用URL重写(使用ISAPI_重写),我发现我的一些图像没有加载,因为.NET似乎不理解我在使用html基标记(在进行URL重写时非常标准和必要): 例如,在我的开发环境中,我有: <base href='http://localhost/venuefinder/Website/'></base> ..当浏览器尝试加载时: http://localhost/images/buttons/search-button.gif 而不是: http:

我在ASP.NET 4下使用URL重写(使用ISAPI_重写),我发现我的一些图像没有加载,因为.NET似乎不理解我在使用html基标记(在进行URL重写时非常标准和必要):

例如,在我的开发环境中,我有:

<base href='http://localhost/venuefinder/Website/'></base>
..当浏览器尝试加载时:

http://localhost/images/buttons/search-button.gif
而不是:

http://localhost/venuefinder/Website/venues/images/buttons/search-button.gif
发生这种情况是因为.NET正在将按钮呈现为:

src="../../../images/buttons/search-button.gif"
…这是不正确的


是否有任何方法可以纠正此问题,以便.NET为图像呈现正确的src属性?(没有所有的../../../etc)

不要在图像中使用
~/
,而是在IIS中创建一个名为
images
的虚拟文件夹,该文件夹映射到您的图像目录(因此:
http://localhost/images
=>
c:\myproject\somesubdir\content\images
)。然后你可以用

<asp:ImageButton runat="server" ImageUrl="/images/button.gif" />

$()。追加(“”)

我真的不知道这将如何解决问题?我原以为虚拟目录可以让我将图像存储到其他地方,但你是说它实际上改变了.NET本身的行为吗?或者你可能建议我真的在根级别创建它,在这种情况下,如果我有多个网站存在此问题,我看不出这将如何工作?我无法为多个网站映射localhost/images/(我开发了大约30个网站)。您可以映射/yourwebsite/images,并将页面中的基本路径设置为;然后您仍然可以使用
/
。因为浏览器现在将/localhost/yourwebsite作为前缀图像的基础。
src="../../../images/buttons/search-button.gif"
<asp:ImageButton runat="server" ImageUrl="/images/button.gif" />
ScriptHelper.RegisterScript("/js/somefile.js")
$().append('<img src="/images/file.jpg"/>')