user9355579
user9355579

Reputation:

Asp.net: relative paths not working when deployed IIS

I spent almost 2-3 good hours on this and im here now, as the question states. The project works fine in VS but when I deploy/publish it through IIS (to access it on local network) some files (well most of them) aren't accessible. This happened when I added the Metronic theme within my web project. The files are like:

  <!-- BEGIN GLOBAL MANDATORY STYLES -->
    <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
    <link href="../../assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="../../assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
    <link href="../../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="../../assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
    <!-- END GLOBAL MANDATORY STYLES -->

OR

<img src="../assets/pages/img/logo.png" alt="place Logo Here" />

Now once its published, it throws me a pile of errors that it could not find any of those files.

State when running on VS

State Once its published to IIS

Notice: the url in both the pictures, the deployed project is under another folder. is it the culprit?

I am trying to figure out a solution that works for both VS debugging and the deployed project.

What I have tried is:

1: https://weblogs.asp.net/scottgu/tip-trick-how-to-run-a-root-site-with-the-local-web-server-using-vs-2005-sp1

2: Deploying asp.net application to root directory in IIS

3: How to avoid deploying ASP.NET MVC3 application in subpath on IIS 7.5

4: ASP.NET WebForms: Why do relative paths within user controls work locally, but not when deployed?

5: IIS virtual directory and ASP.NET directory paths

6: Relative path from site root

Upvotes: 2

Views: 6610

Answers (2)

EdSF
EdSF

Reputation: 12371

g2 is the folder that I created inside wwwroot which has the published files

  • If your intent was to make that a "sub application" (of whatever is the "parent" in wwwroot then it can be a "virtual directory" or a "sub application"

  • If your intent was to publish it as it's own application, separate from any other, then you don't have to publish it under wwwroot. You create new IIS sites.

The previous answer using ~/ is based on what is defined as the application root

Hth...

Upvotes: 0

Andreas
Andreas

Reputation: 992

You might want to use absolute paths starting with '~/' as the base directory of your Web Site / Web App.

e.g. "~/assets/pages/img/logo.png"

and when working in Code Behind use the

Server.MapPath("~/") 

as Base Folder.

Upvotes: 3

Related Questions