ASP.NET 5和Angular路由不适用于dnx rc1 [英] ASP.NET 5 and Angular Routing not working on dnx rc1

查看:44
本文介绍了ASP.NET 5和Angular路由不适用于dnx rc1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用ASP.NET 5(dnxcore50和dnx451)构建的项目.它正在为我的AngularJS脚本提供请求.在构建项目时,我使用的是Microsoft beta 5依赖项,并使用了重写规则将所有请求发送到index.html,因此我的角度路由工作得很好.但是今天我不得不升级到rc1依赖项,现在我的重写无法正常进行,而我的路线上只有404.这些新库将这些奇怪的代码行添加到了我的web.config

Hi I have a project built in ASP.NET 5 (dnxcore50 and dnx451). It is serving the requests for my AngularJS scripts. When I built the project I was using the Microsoft beta 5 dependencies and using a rewrite rule to send all the requests to index.html and so my angular routing would work just fine. But today I had to upgrade to the rc1 dependencies and now my rewrite is not working and I'm just getting a 404 on my route. This new libraries added this weird lines of code to my web.config

  <handlers>
  <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />

有没有一种方法可以设置路由,以便它与angular一起工作,例如,如果我去localhost/shop,它将重定向到index.html,而我的角度路由将接管.

Is there a way how can I set my routing so that it works with angular for example if I go to localhost/shop it will redirect it to index.html and my angular routing will take over.

推荐答案

我使用类似的设置,并且在 Startup.cs

I am on similar setup and I have in Configure in Startup.cs,

    app.UseDefaultFiles();

    app.UseStaticFiles();

    app.UseIISPlatformHandler();

以及 web.config system.webServer 中的重写规则,需要能够同时提供Web api和index.html角度应用程序:

and a rewrite rule in system.webServer in web.config, needed that to be able to have both web api and index.html angular app served:

    <rewrite>
      <rules>
        <!--Redirect selected traffic to index -->
        <rule name="Index Rule" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_URI}" matchType="Pattern" pattern="^/api/" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>

您可能还需要自己制定规则的类似内容

You may need something similar too with your own rules

这篇关于ASP.NET 5和Angular路由不适用于dnx rc1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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