Can not find resources (javascript, css) when deploying project in IIS

1

I would like to ask about a problem that I have been experiencing with IIS.

Let's say that I deploy my site in C:wwwRoot / MyProjectName / (todos los archivos de sitio aquí ) . The deployment seems to work without any problem.

Then when I go to the browser and try http : //MyServerIp/MyProjectName/index.html , the start site starts loading, but when I check the chrome console all the resources included in index.html (CSS, JS), throw an error saying that:

  

Http: //MyServerIp/SomeFile.js I experience an error while trying to   get the resource, because the file could not be found.

Of course, the problem is because the site should be looking for these files at: http : //MyServerIp/MyProjectName/SomeFile.js .

So for some reason IIS is removing the: MyProjectName from the route.

The site is a C # based site with AngularJS.

I hope someone can help me.

Thanks!

    
asked by Santiago Arango Toro 23.05.2016 в 15:43
source

2 answers

1

There are two scenarios with which the solution varies, these are or your site is published as Web application on a website or is published as website and is only a subfolder . The difference is that when referencing the root of your application it could be interpreted differently.

When you are working with a web application , either web forms or mvc you can use the path "~/" to reference the root of your application which in this case is http://tuservidoroip/tuaplicacion . But, when you are working with a subfolder of a site this will not work. This way of referencing the root of the application only works when your HTML document goes through some processing of ASP and this is the one that rewrites the routes. So you're not sure, opt for the next option. Example:

<script src='@Url.Content("~/path/tuscript.js")' type="text/javascript"></script>

When you are working with a subfolder within a site you can choose to redirect from the root of your server using the "/" character. Example:

<script src="/tuservidor/tuproyecto/path/tuscrip.js" type="text/javascript"></script>

NOTE: When you use the '~' character and you are not having ASP process this address (For example, do not use the Url.Content method) the system will write the URL and follow you giving problem, so just use it when you're sure that ASP processes it before.

    
answered by 08.09.2016 в 01:50
0

add your resources this way:

Javascripts:

<script src="@Url.Content("~/Scripts/myscript.js")" type="text/javascript"></script>

CSS:

<link href="@Url.Content("~/Content/fonts.css")" rel="stylesheet"/>

Greetings

    
answered by 23.05.2016 в 23:09