gciochina
gciochina

Reputation: 1201

.Net 4.0 web application publish - unable to locate resources

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?

Upvotes: 1

Views: 373

Answers (1)

Grhm
Grhm

Reputation: 6854

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

Upvotes: 1

Related Questions