Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative path in ASP.NET

<head runat="server">
    <meta charset="UTF-8" />
    <title>Make Games with Scirra Software</title>
    <meta name="description" content="Game making with Construct." />
    <meta name="keywords" content="game maker, game builder, html5, create games, games creator" />
    <link rel="stylesheet" href="~/css/default.css" />
    <link rel="stylesheet" href="~/plugins/coin-slider/coin-slider-styles.css" />
    <link rel="shortcut icon" href="~/images/favicon.ico" />
    <link rel="apple-touch-icon" href="~/images/favicon_apple.png" />
    <script src="~/js/googleAnalytics.js"></script>
</head>

Renders as:

<head>
    <meta charset="UTF-8" />
    <title>Make Games with Scirra Software</title>
    <meta name="description" content="Game making with Construct." />
    <meta name="keywords" content="game maker, game builder, html5, create games, games creator" />
    <link rel="stylesheet" href="../css/default.css" />
    <link rel="stylesheet" href="../plugins/coin-slider/coin-slider-styles.css" />
    <link rel="shortcut icon" href="../images/favicon.ico" />
    <link rel="apple-touch-icon" href="../images/favicon_apple.png" />
    <script src="~/js/googleAnalytics.js"></script>
</head>

Why is the JavaScript URL ~/ and not ../?

like image 425
Tom Gullen Avatar asked Mar 06 '11 00:03

Tom Gullen


1 Answers

Strange implementation indeed, but unfortunately that is the way ASP.NET handles this. Here is what I do to compensate:

<script src="<%=ResolveClientUrl("~/js/googleAnalytics.js")%>"></script>
like image 92
dana Avatar answered Sep 19 '22 13:09

dana