Relative path does not work when deploying website

I have a website that has a relative path to a stylesheet that looks like this: /stylesheets/main.css. Now this works great when I run the site in Visual Studio. But when I deploy the site to our Windows Server 2003, the path stops working. If I go back to the code and change the path from "/stylesheets/main.css" to "stylesheets / main.css", the site works fine on the server. I have another site on another server that uses the same path style ("/stylesheets/main.css") and the stylesheet without any problems. I really do not want to change all the paths, and I'm not even sure if this is a problem with the code or server. Any help or ideas would be great. Thank.

+3
source share
6 answers

Is the site deployed at the root of the domain? If the site is in

http://example.com/somefolder/

then the path /stylesheet/main.csswill be interpreted as

http://example.com/stylesheet/main.css

but not

http://example.com/somefolder/stylesheet/main.css

As pointed out by @Kit, you can get around this by resolving the path to your application folder. I often did this in ASP.NET as follows:

<link rel="stylesheet" type="text/xss" href="<%= ResolveUrl("~/stylesheet/main.css") %>"/>

If this is not a problem, you will have to tell a little more.

+9
source

In ASP.NET many times you will need to use the tilde ( ~) to get the application root directory , so your paths will look like~/stylesheets/main.css

, /, , , , , , :

: foo.net , app /stylesheet foo.net/stylesheet not foo.net/app/stylesheet

+3

. , . , - :

<head runat="server">
  <link href="~/stylesheet/main.css" type="text/css" rel="stylesheet" />
</head>

(~) , -. , . , , .

0

URL-

/path_preceded_by_a_slash

... , , DocumentRoot, , .

, . , .

0

(,/images/cool_image.gif ') , IIS.

, Visual Studio ASP.NET Web Application, - IIS -.

Visual Studio ASP.NET Web Site, " ", , , IIS, IIS. , "-".

- Visual Studio - google it - .

0

I know this is an old thread, but for future readers I would like to add this, I noticed that sometimes, in order to make virtual paths work, it is necessary to remove the runat = "server" part from the head and when dragging any file onto the page belonging to the main folder, you need to remove "~" or "..." from the path. something like that:

    <!DOCTYPE html>

<html>
<head>
 <script src="javascript/Red/jquery.min.js"></script>
</head>
0
source

Source: https://habr.com/ru/post/1736167/


All Articles