Asp.net

ASP.NET 中的相對路徑

  • July 22, 2016
<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>

呈現為:

<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>

為什麼是 JavaScript URL~/而不是../

確實很奇怪的實現,但不幸的是,這是 ASP.NET 處理此問題的方式。這是我做的補償:

<script src="<%=ResolveClientUrl("~/js/googleAnalytics.js")%>"></script>

引用自:https://stackoverflow.com/questions/5207776