Tony
Tony

Reputation: 55

URLs not working the same

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.

Upvotes: 1

Views: 72

Answers (1)

Oded
Oded

Reputation: 498992

Add a runat="server" to the img element and things will work as you expect.

~ is interpreted correctly on the page only in server side controls (items in the head element are parsed server side when it comes to the path).

Upvotes: 1

Related Questions