2

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

  • is `g2` your _application_ root (and marked as such)? Clarify how you set this up in IIS (particularly what `g2` is). – EdSF Feb 13 '18 at 15:25
  • g2 is the folder that I created inside wwwroot which has the published files –  Feb 13 '18 at 15:26

2 Answers2

3

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.

Andreas
  • 828
  • 4
  • 15
  • what about the rest of the files? like this one: `` and when working in Code Behind use the, im sorry what? –  Feb 13 '18 at 15:23
  • href="../../assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" would then be href="~/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" if assets is in your base directory. – Andreas Feb 13 '18 at 15:26
  • Code Behind is either your Website.aspx.cs or the Code in the Controller when you are using MVC. – Andreas Feb 13 '18 at 15:28
  • sure. let me check this –  Feb 13 '18 at 15:30
0

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...

EdSF
  • 11,753
  • 6
  • 42
  • 83