angular 2 azure部署刷新错误:您正在寻找的资源已被删除,名称已更改或暂时不可用 [英] angular 2 azure deploy refresh error : The resource you are looking for has been removed, had its name changed, or is temporarily unavailable

查看:64
本文介绍了angular 2 azure部署刷新错误:您正在寻找的资源已被删除,名称已更改或暂时不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实现基本路由的Angular 2 rc-2应用程序,路径是/path1这是默认路径和/path2.主路径/重定向到/path1.当我在本地(精简服务器)运行它时,一切正常.我设法将此应用程序部署到Azure Web应用程序.如果我在/path1/path2中刷新页面时,该应用程序正常运行,但出现以下错误:The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

I have an Angular 2 rc-2 app with basic routing implemented.The paths are /path1 which is the default path and /path2.The home path / redirects to /path1. When I run it locally (lite-server) everything works fine. I managed to deploy this app to an Azure web app. The app works OK BUT if I refresh the page when I m in /path1 or /path2 I get this error : The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

一种可能的方法是实现URL重写.我在项目中添加了一个web.config文件

A possible approach is to implement url rewrite. I added a web.config file in my project

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
    <system.webServer>
        <rewrite>
        <rules>
        <clear />

         <!-- check if its path1 url and navigate to default page -->
        <rule name="Path1 Request" enabled="true" stopProcessing="true">
        <match url="^path1" />
        <action type="Redirect" url="/index.html" logRewrittenUrl="true" />
        </rule>

         <!-- check if its path2 url and navigate to default page -->
        <rule name="Path2 Request" enabled="true" stopProcessing="true">
        <match url="^path2" />
        <action type="Redirect" url="/index.html" logRewrittenUrl="true" />
        </rule>

         </rules>
        </rewrite>
    </system.webServer>
</configuration>

在这种情况下,我可以刷新而不会收到此错误消息.但是任何刷新都会将我重定向到默认URL.我从/path2刷新,它将我重定向到/path1(默认网址).

In this case I can make a refresh without getting this error message.But any refresh redirects me to the default url. I refresh from /path2 and it redirects me to /path1 (default url).

是否有任何改善刷新的想法? :)

Any thoughts to improve refresh ? :)

推荐答案

您必须将 web.config 文件添加到根Angular2应用中.这就是Azure服务器(IIS Server)的工作方式.

You have to add web.config file to your root Angular2 app. That's how Azure servers (IIS Server) works.

我正在使用webpack,因此将其放在 src 文件夹中.部署时,请不要忘记将其复制到您的 dist 文件夹中.我使用了 CopyWebpackPlugin 来设置要复制的Webpack.

Im using webpack so I put it on src folder. Don't forget to copy it to your dist folder when you depploy. I used CopyWebpackPlugin to setup my webpack to copy it.

这是web.config文件:

This is the web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
                <rule name="AngularJS Routes" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

它有2条规则:

It has 2 rules:

第一条规则是将所有呼叫重定向到https.如果不使用https,请将其删除.

1st rule is to redirect all calls to https. Remove it if you don't use https.

第二条规则是解决您的问题.我在这里获得了第二条规则的引用(由于来自www.reddit.com的用户 gravityaddiction ):

2nd rule is to fix your problem. I got reference of 2nd rule here (thanks to user gravityaddiction from www.reddit.com):

这篇关于angular 2 azure部署刷新错误:您正在寻找的资源已被删除,名称已更改或暂时不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆