1

I've got two different URLs in the <link> and <img> tag below:

...
<head id="Head1" runat="server">
<link rel="stylesheet" type="text/css" href="~/css/site.css" />
<title></title>
</head>
<body>
    <form id="form1" runat="server" >
    <div id="header">
    <img src="~/img/title.png" alt="ClearBox" />
...

This html is in a master file and used by multiple pages. In this particular case its used by a page in the /login directory.

When its served up by IIS, the <link> url becomes ../css/site.css which correctly points to the css file.

The <img> url remains ~/img/title.png.

The master file css URL works for different pages, but the image URL remains the same.

If I change the <img> URL to img/title.png, it works correctly on the main page, but no those in the /login directory.

Any thoughts about how to get image url to work like the link url?

In a more general sense, I can fix all of this with absolute URLs, but I'd like to keep relative URLs, and not do run time constructed URLs because this application will be on different sites.

4

1 に答える 1

1

runat="server"要素に aを追加すると、img期待どおりに機能します。

~サーバー側のコントロールでのみ、ページ上で正しく解釈されます (head要素内の項目は、パスに関してはサーバー側で解析されます)。

于 2012-10-12T15:53:24.330 に答える