How to leave the relative folder path?

Asked

Viewed 392 times

2

I developed a project in ASP.NET MVC and now I’m going up to the server.

Turns out on my local machine, it takes the localhost address, something like this:

http://127.0.0.1:8080/

But when publishing on the server, it’s there:

www.dominio.com/meuprojeto

So here comes the trouble.

I had to rename all references to my javascript, css etc.

where I was standing :

<script type="text/javascript" src="/Js/exemplo.js"></script>

I had to rename to:

<script type="text/javascript" src="/meuprojeto/Js/exemplo.js"></script>

Is there any other solution without me having to rename everything ?

because the project on my local machine now gets lost, and on the server gets right.

  • if you can take the / initial or exchange for ./ so it uses the relative path of the folder, ie with its index is in www.dominio.com/meuprojeto when using src='./Js/exemplo.js' will equal src='www.dominio.com/meuprojeto/Js/exemplo.js' and locally if your index this in localhost:8080 he had stayed src='localhost:8080/Js/exemplo.js'

1 answer

3


Your links are starting with / or absolute path. To use path relative to the current folder use ./ or without the / initial.

<!-- <script type="text/javascript" src="/Js/exemplo.js"></script> -->
<script type="text/javascript" src="./Js/exemplo.js"></script>

so it must work the same being both in the http://www.dominio.com/meuprojeto/ how much http://127.0.0.1:8080/

src starting with:

//: Automated selection of protocol (http , https) example of use: <script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> / : Root directory ./ : Current directory ../ : A directory above the current one, example www.dominio.com/meuprojeto/ the directory used is the www.dominio.com/ ../../ : Two directories above the current (and so on)
  • thanks @Icaro Martins. but because there are people who do not want to help hinder negativing the question ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.