Asp.net:部署 IIS 时相对路径不起作用
Asp.net: relative paths not working when deployed IIS
正如问题所述,我在这上面花了将近 2-3 个小时,现在我在这里。该项目在 VS 中运行良好,但是当我通过 IIS deploy/publish 它(在本地网络上访问它)时,一些文件(大部分)无法访问。当我在我的网络项目中添加 Metronic 主题时发生了这种情况。文件如下:
<!-- 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 -->
或
<img src="../assets/pages/img/logo.png" alt="place Logo Here" />
现在一旦它发布,它会抛出一堆错误,它找不到任何这些文件。
注意:两张图中的url,部署的项目在另一个文件夹下。是罪魁祸首吗?
我正在尝试找出一个适用于 VS 调试和已部署项目的解决方案。
我试过的是:
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
您可能希望使用以“~/”开头的绝对路径作为网站/Web 应用程序的基本目录。
e.g. "~/assets/pages/img/logo.png"
并且在代码隐藏中工作时使用
Server.MapPath("~/")
作为基本文件夹。
g2
is the folder that I created inside wwwroot which has the published files
如果您的意图是使它成为 "sub application"(无论 wwwroot
中的 "parent" 是什么,那么它可以是 "virtual directory" or a "sub application"
如果您的目的是将其作为独立的应用程序发布,与任何其他应用程序分开,那么您不必在 wwwroot
下发布它。您创建新的 IIS sites.
之前使用 ~/
的答案是基于定义为 应用程序根目录
第...
正如问题所述,我在这上面花了将近 2-3 个小时,现在我在这里。该项目在 VS 中运行良好,但是当我通过 IIS deploy/publish 它(在本地网络上访问它)时,一些文件(大部分)无法访问。当我在我的网络项目中添加 Metronic 主题时发生了这种情况。文件如下:
<!-- 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 -->
或
<img src="../assets/pages/img/logo.png" alt="place Logo Here" />
现在一旦它发布,它会抛出一堆错误,它找不到任何这些文件。
注意:两张图中的url,部署的项目在另一个文件夹下。是罪魁祸首吗?
我正在尝试找出一个适用于 VS 调试和已部署项目的解决方案。
我试过的是:
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
您可能希望使用以“~/”开头的绝对路径作为网站/Web 应用程序的基本目录。
e.g. "~/assets/pages/img/logo.png"
并且在代码隐藏中工作时使用
Server.MapPath("~/")
作为基本文件夹。
g2
is the folder that I created inside wwwroot which has the published files
如果您的意图是使它成为 "sub application"(无论
wwwroot
中的 "parent" 是什么,那么它可以是 "virtual directory" or a "sub application"如果您的目的是将其作为独立的应用程序发布,与任何其他应用程序分开,那么您不必在
wwwroot
下发布它。您创建新的 IIS sites.
之前使用 ~/
的答案是基于定义为 应用程序根目录
第...