移动到IIS虚拟目录时,Angular 2应用程序无法正常工作 [英] Angular 2 application not working when moved into IIS virtual directory
问题描述
我在本地PC上的IIS(inetmgr)上创建了一个虚拟目录,然后将其转换为IIS Web应用程序。 Web应用程序的根目录是: http:// localhost / xyz / 部署并运行应用程序时,我得到以下内容浏览器中的错误:
I have created a Virtual Directory on IIS (inetmgr) on my local PC and later converted it into IIS Web Application. The web application's root is: http://localhost/xyz/ When deployed and ran the application, I get the following error in the browser:
找不到所有html组件404错误。
All html components 404 not found errors.
在web.config中添加了重写规则。我将index.html的基本href更改为./xyz或./但没有运气。
Added rewrite rules in web.config. I changed index.html's base href to ./xyz or ./ but no luck.
如果我将其部署到根目录,一切都会解决 - 不确定出了什么问题。
If I deploy it to root directory, everything resolves - not sure what's going wrong.
推荐答案
1。启用 xyz
文件夹作为Web应用程序文件夹(见下图)
1. Enable xyz
folder as a web application folder (See below picture)
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
希望有所帮助!
这篇关于移动到IIS虚拟目录时,Angular 2应用程序无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!