Search code examples
asp.netmaster-pages

Links in master page with tilde URLs give 404 depending on the page


I have a master page with links to other pages in the site. Those links use tilde paths (like "~/dir1/page2.aspx"). On most of the pages in the site that use this master page, there is no problem.

The problem only occurs on a few pages that use the master page. The links are VERY wrong; it tries to use the ~ as part of the link (so they are "http://server.domain.com/~/dir1/page2.aspx").

It's as if it is treating the tilde as a literal under certain circumstances.


Solution

  • Sounds like you're not properly resolving the URLs.

    Are you writing ResolveUrl("~/")?

    Also make sure that if you use ~/ that your controls are runat="server".