1

So I'm publishing my .Net 4.0 ASP.NET web application under c:\inetpub\wwwroot\myTestApp. However, whenever I try to access it via the browser (using http://localhost/myTestApp) it seems that the application cannot find any resources (scripts, images, etc)

When I'm looking at the requests, i see that it somehow requests http://localhost/myTestApp/myTestApp/Scripts/jquery.validate.min.js instead of http://localhost/myTestApp/Scripts/jquery.validate.min.js

More info:
1. When I'm debugging using development server/ IIS, it works OK.
2. If I publish the application directly as a website, it also works OK.
3. The folder where I'm trying to publish the application is under "Default Web Site" and I've already configured it as a web application under IIS

What am i doing wrong?

Grhm
  • 6,726
  • 4
  • 40
  • 64
gciochina
  • 1,182
  • 16
  • 23
  • The VS dev server always servers from a `/MyApp` - look at the properties pane for your website project - it's near the bottom if I recall, Change it to `/` and your dev server should run the same as the default website – Basic Apr 03 '12 at 10:37
  • Yes,I can see that. but my problem is not with the VS dev server; it happens when i publish my app on IIS, as a web application, under a web site. – gciochina Apr 03 '12 at 10:48
  • Yes, I'm aware that the problem is when using it on the live site but if your dev environment matches your web server, any problems you have in IIS will be replicated in VS, allowing you to develop the site correctly :) – Basic Apr 03 '12 at 16:41

1 Answers1

1

In your aspx files how are you referring to your resources? I suspect your having issues with absolute, relative and application relative paths.

Instead of

<script src="myTestApp/Scripts/jquery.validate.min.js" />

to give an absolute url, use one of the following

<script src="~/Scripts/jquery.validate.min.js" runat="server" />
<script src="<%= ResolveClientUrl("~/Scripts/jquery.validate.min.js") %>" />

alternatively use need to use relative paths e.g.

<script src="../Scripts/jquery.validate.min.js" runat="server" />

I'd avoid relative if you can, as it can get awkward and confusing where it is relative from if you have a master page in one directory, the pages in another, and child controls at a third location.

Basically, you use the ~ on the server side to refer to the root of your application.

I believe your issue stems from the fact that the dev server and IIS have the application root at different levels (one at http://localhost/ and the other at http://localhost/myTestApp/), and you've coded for one and not the other.

EDIT:

See also Relative Paths in Javascript in an external file

Community
  • 1
  • 1
Grhm
  • 6,726
  • 4
  • 40
  • 64
  • 2
    Just to add to Grhm's answer, if you use MVC there are different ways to achieve this - See eg http://stackoverflow.com/a/3816846/156755 – Basic Apr 03 '12 at 17:13