0

当我尝试从子文件夹文件访问 CSS 或 JS 文件时,我无法获得正确的路径en/Default.aspx

我有以下文件夹结构

Default.aspx
  en/Default.aspx
  en/MasterPage.master
  ar/Default.aspx
  ar/MasterPage.master
scripts/slider/script.js
styles/slider-en.css
scripts/slider/jquery.easing.js

en/Default.aspx文件中的代码

<%@ Page Title="" Language="C#" MasterPageFile="~/en/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<%@ Register Src="~/en/UserControls/ucSliderHP.ascx" TagName="ucSlider"  TagPrefix="uc"%>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<script src="../scripts/slider/jquery.easing.js" type="text/javascript"></script>
<script src="../scripts/slider/script.js" type="text/javascript"></script>
<link href="<%= Page.ResolveUrl("./styles/slider-en.css") %>" rel="stylesheet" type="text/css" />

<div id="content-container-750">
    <!-- Slider   -->
    <!-- Sidebar   -->
<div id="sidebar-container-240"></div>
<!-- Sidebar   -->
    <div id="Slider-Wrapper-750x300">
       <uc:ucSlider ID="NewsSlider" runat="server" />       
    </div>
     <!-- Slider   -->

      <!-- Banner   -->
      <div id="content-Banner-750x100HP">
      </div>
      <!-- Banner   -->
      <!-- Article   -->
      <div id="article-wrapperHP">
      </div>
      <!-- Article   -->
</div>

</asp:Content>

当我使用../路径时,它总是返回路径为 http://localhost:49831/en/scripts/slider/script.js

当我使用 `Page.ResolveURL 或 ResolveURL 它返回我的路径为

http://localhost:49831/website/en/Default.aspx?language=en-us&issue=5

我不知道我应该怎么做我尝试过../../它也不起作用

4

3 回答 3

0

尝试使用 ResolveUrl:

<script src="<%=ResolveUrl("~/scripts/slider/jquery.easing.js")%>"  type="text/javascript"></script>

代替

<script src="../scripts/slider/jquery.easing.js" type="text/javascript"></script>
于 2012-12-18T11:45:14.443 回答
0

您还可以添加波浪号 ( ~) 并runat="server"让 ASP .NET 根据根目录解析 url。

例如

<link href='~/styles/slider-en.css' rel="stylesheet" type="text/css" runat="server"/>

查看此问题的其他选项

于 2012-12-18T11:45:16.123 回答
0
You can Use
    /scripts/slider/jquery.easing.js
<script src="/scripts/slider/jquery.easing.js" type="text/javascript"></script>


"/"  

指根。

于 2012-12-18T12:15:08.350 回答