0

I have a page in a root folder and another page in a files folder inside the root.

folder structure

->root->files->foo.aspx
->root->default.aspx
->root->foo.js

when i do a server.transfer from the page inside the files folder(foo.aspx) to the page in root(default.aspx), my javascripts(foo.js) doesn't load as page looks for the files in the subfolder(files). That is, the page looks for the javascript in ->root->files.

Is there a way to ask the server to look for javascript in the place where the file is??

PS:this is just an example not real scenario, I have different folders level that need to reference the file at root.

response.redirect is not the answer I am looking for.

Thanks in advance

user1
  • 1,063
  • 1
  • 8
  • 28
  • 1
    What is the syntax you are using for the reference to the js file? It should be relative to the app root. – AaronLS Mar 07 '13 at 23:57

1 Answers1

1

The additional requests to retrieve content such as .js files, images etc. is done by the browser after the page has been retrieved.
Since Server.Transfer displays a different page without changing the URL, the browser thinks the url is http://yoursite.com/files/foo.aspx and not http://yoursite.com/default.aspx.
In your HTML you state that the additional content (the .js file) is located in the same directory:

<script src="foo.js" />

and since the browser thinks he's in the files directory, he looks for it there .

(This is by design...)

A workaround is putting the full URL instead of the relative one:

<script src="http://yoursite.com/foo.js" />

or even

<script src="/foo.js" />
Blachshma
  • 17,097
  • 4
  • 58
  • 72