2012-12-18 99 views
0

當我嘗試從子文件夾en/Default.aspx文件訪問它們時,我無法獲得CSS或JS文件的正確路徑。在asp.net中無法訪問css或js文件的路徑

我有以下文件夾結構

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

,當我使用`頁。 ResolveURL或ResolveURL它返回我的路徑爲

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

我不知道我應該怎麼做我想../../也不會工作,要麼

回答

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

您還可以添加代字號(~)和runat="server"以獲得A SP .NET來解析基於根的URL。

例如

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

See other options on this question

0
You can Use 
    /scripts/slider/jquery.easing.js 
<script src="/scripts/slider/jquery.easing.js" type="text/javascript"></script> 


"/" 

手段根。