Azure 上的 Angular2 应用程序 "You do not have permission to view this directory or page"子路由

标签 angular azure iis angular2-routing

我已经发布了 Angular2 应用程序并将其部署在 Azure Web Apps 上。如果我通过浏览到其根目录来启动该应用程序,则该应用程序可以正常工作: http://cafeserver.azurewebsites.net/Web/

但是,如果我直接浏览到应用程序中的子路由,例如: http://cafeserver.azurewebsites.net/Web/customers

它将抛出一个错误,指出“您无权查看此目录或页面”。

如何解决这个问题?

最佳答案

您需要更新 web.config 以将所有路由重定向到索引页面,以便 Angular 路由可以启动。我使用以下配置将 SPA 部署到 Azure:

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="SPA">
                    <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>
        </rewrite>
    </system.webServer>
</configuration>

请注意,我的设置会免除对包含 /api 的文件、目录和请求 URI 的请求,因为我将其保留用于后端 HTTP 路由。您可以根据您的豁免需求更新您的。

关于Azure 上的 Angular2 应用程序 "You do not have permission to view this directory or page"子路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46182615/

相关文章:

angular - 可观察到的 : Cancel previous http request on new subscription call

javascript - glyphicon glyphicon-refresh glyphicon-spin 在 Angular2 中不起作用

c# - 在 Windows 8.1 中启用 Windows 身份验证

angular - 使用 Angular Renderer2 在 svg rect 上添加 onclick 事件

javascript - 为什么不能在 ngFor 中使用 var 而不是 let

Azure Cloud Shell 加载延迟约 20 分钟

Azure Function - 限制服务总线触发

在删除用户帐户之前将资源迁移到新帐户的 Azure

c# - 如何使用 C# 从虚拟目录创建 HTTP 重定向

php - COM 无法在 IIS PHP 版本 7.2.9 中工作