ASP.NET Web App Relative Paths

Go To StackoverFlow.com

2

What's the difference between following relative paths?

<script type="text/javascript" src="../Scripts/jquery-1.2.6.js"></script>
<script type="text/javascript" src="../../Scripts/jquery-1.2.6.js"></script>
<script type="text/javascript" src="/Scripts/jquery-1.2.6.js"></script>
<script type="text/javascript" src="~/Scripts/jquery-1.2.6.js"></script>
  • Which refers what?
  • e.g. I have a web app names ASPWP1 and folder structure as follows

  • ASPWP1->Folder1

  • ASPWP1->Folder1->JS1.js
  • ASPWP1->Folder1->Sample1.aspx
  • ASPWP1->Folder2
  • ASPWP1->Folder2->JS2.js
  • ASPWP1->Folder2->Sample2.aspx
  • ASPWP1->Folder3->JS3.js, JS4.js

  • How to refer JS1 in sample1.aspx?
  • How to refer JS1 in Sample2.aspx?
  • How to refer JS3/JS4 in Sample1.aspx

Please guide me in understanding relative paths.

Thanks in advance

2012-04-04 07:55
by Santhosh


2

The tilde (~) refers to HttpRuntime.AppDomainAppVirtualPath which is usually the route of the virtual directory.

Have you tested: < script type="text/javascript" src="~/Scripts/jquery-1.2.6.js">

I'm surprised it would actually reference the file without a runat="server" tag as JavaScript would not be able to determine the value of HttpRuntime.AppDomainAppVirtualPath.

I have included a MSDN source which you should read to help you understand this better.

http://msdn.microsoft.com/en-us/library/ms178116.aspx

2012-04-04 08:00
by Darren
Ads