2016-10-10 40 views
0

我有一个使用Visual Studio 2015和.NET MVC 4.5.2构建的项目,最近开始使用Angular 2作为前端。在介绍Angular 2之前,我有诸如/ Plan/Dashboard和/ Plan/Production等路线。我使用JQuery/Ajax来替换内容,而不是进行整页刷新,但是URL永远不会改变,所以点击forward/back/refresh不会像你期望的那样工作。现在我正在使用Angular 2,URL会相应更改,以便后退/前进按钮可以工作,但刷新页面不起作用。例如,如果Angular 2的路由将我的URL从/ Plan/Production更改为/ Plan/Production/Selling并刷新它,我相信.NET会搜索该路由并找不到它,导致URL更改为https://localhost:44301/Error/NotFound?aspxerrorpath=/Plan/Production/Selling内容只显示“错误”。我的问题是,有没有办法告诉.NET忽略任何以/ Plan/Production /开头并允许Angular 2处理路由的路线?我还需要与其他页面一起完成此操作,但现在我正在专注于/计划/生产。.NET MVC 4.5.2:忽略某些路线并让Angular 2处理它们

回答

2

尝试这样的事情在你的web.config:

<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <rule name="Redirect to NG2" patternSyntax="Wildcard" stopProcessing="true"> 
        <match url="Plan/Production/*" /> 
        <action type="Rewrite" url="/Plan/Production" /> 
        <conditions> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        </conditions> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 
</configuration> 

您将需要有重写模块安装到使用这个网址。

+0

这没有奏效。那里还有另外一条规则,我想知道这是否会因为某种原因与它冲突?以下是规则: <动作类型= “重定向” URL = “HTTPS:// {HTTP_HOST}/{R 1}” redirectType = “SeeOther”/> Brett

+1

的stopProcessing = “真” 表示当处理该规则时,将不会处理其他规则。尝试在https规则上将其设置为false。 –

+0

我尝试过,但不幸的是它并没有改变任何东西 – Brett