ASP.NET Core RC2中的网址重写

twilliams

如何在ASP.NET Core RC2中完成URL重写?当我刷新页面时,从RC1迁移到RC2破坏了我的Angular 2路由。

之前,我在wwwroot中的web.config中使用了这样的规则。使用RC2,我什至不确定我的wwwroot中是否应该有一个web.config,还是我的项目基础中只有一个。

这是我的基本web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="true" stdoutLogEnabled="true" />
  </system.webServer>
</configuration>

这是我的wwwroot web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <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" />
            <add input="{REQUEST_URI}" matchType="Pattern" pattern="^/account/" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

当我刷新角度2路由时,我Status Code: 404; Not Found从ASP.NET获得了一个

亚当·科普斯基(AdamKopciński)

我发现史蒂夫·桑德森(Steve Sanderson)的解决方案似乎有效。他为RouteBuilder写了扩展名。您可以通过调用扩展方法MapSpaFallbackRoute在Setup.cs中对其进行配置

https://github.com/aspnet/JavaScriptServices

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
                routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
            });

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ASP.NET Core RC2中的网址重写

来自分类Dev

ASP.NET Core rc2中的Cookie

来自分类Dev

.NET Core RC2中的小写网址

来自分类Dev

ASP Net Core 1 RC2 AccountController注入

来自分类Dev

是否发布了ASP.NET Core RC2?

来自分类Dev

ASP.NET Core 1.0 RC2中的“找不到类型或名称空间名称”

来自分类Dev

如何禁用ASP.NET Core rc2中的浏览器缓存?

来自分类Dev

如何在ASP.NET Core 1.0 RC2中加载程序集

来自分类Dev

在ASP.NET MVC Core应用程序(RC2)中显示项目版本

来自分类Dev

在ASP.NET Core 1.0 RC2中使用RSS的正确方法

来自分类Dev

无法在IISExpress中启动ASP.NET Core RC2 Web应用程序

来自分类Dev

如何在ASP.NET Core RC2中制作Websocket服务器?

来自分类Dev

如何在ASP.NET Core RC2中制作Websocket服务器?

来自分类Dev

ASP.NET Core 1.0 RC2中的“找不到类型或名称空间名称”

来自分类Dev

无法在ASP.NET Core RC2中导入Oracle Client

来自分类Dev

无法添加对.net core类库asp.net core rc2的引用

来自分类Dev

.NET Core RC2 applicationhost.config与ASP.NET .NET 4.6不兼容?

来自分类Dev

如何在 Visual Studio Team Services (VSTS) 中构建 ASP.NET Core 2 RC2 项目?

来自分类Dev

无法让ConfigurationBuilder从ASP.NET Core 1.0 RC2的xunit类库中的appsettings.json中读取

来自分类Dev

无法让ConfigurationBuilder从ASP.NET Core 1.0 RC2的xunit类库中的appsettings.json中读取

来自分类Dev

将Asp.Net Core RC1迁移到RC2后的问题

来自分类Dev

Razor页面在运行时无法在ASP.NET Core RC2中看到引用的类库

来自分类Dev

如何在ASP.NET Core RC2应用程序中手动重新加载IOptions

来自分类Dev

如何在ASP.NET Core 1.0 RC2中将实例注册到ServiceCollection

来自分类Dev

在ASP.NET Core RC2中使用AddAuthentication时的模棱两可的调用

来自分类Dev

如何在ASP.NET Core RC2中获取控制器的自定义属性

来自分类Dev

Razor页面在运行时无法在ASP.NET Core RC2中看到引用的类库

来自分类Dev

在ASP.NET Core应用程序(RC2)中使用net451库

来自分类Dev

在ASP Core 1.0 RC2中无法远程触发

Related 相关文章

  1. 1

    ASP.NET Core RC2中的网址重写

  2. 2

    ASP.NET Core rc2中的Cookie

  3. 3

    .NET Core RC2中的小写网址

  4. 4

    ASP Net Core 1 RC2 AccountController注入

  5. 5

    是否发布了ASP.NET Core RC2?

  6. 6

    ASP.NET Core 1.0 RC2中的“找不到类型或名称空间名称”

  7. 7

    如何禁用ASP.NET Core rc2中的浏览器缓存?

  8. 8

    如何在ASP.NET Core 1.0 RC2中加载程序集

  9. 9

    在ASP.NET MVC Core应用程序(RC2)中显示项目版本

  10. 10

    在ASP.NET Core 1.0 RC2中使用RSS的正确方法

  11. 11

    无法在IISExpress中启动ASP.NET Core RC2 Web应用程序

  12. 12

    如何在ASP.NET Core RC2中制作Websocket服务器?

  13. 13

    如何在ASP.NET Core RC2中制作Websocket服务器?

  14. 14

    ASP.NET Core 1.0 RC2中的“找不到类型或名称空间名称”

  15. 15

    无法在ASP.NET Core RC2中导入Oracle Client

  16. 16

    无法添加对.net core类库asp.net core rc2的引用

  17. 17

    .NET Core RC2 applicationhost.config与ASP.NET .NET 4.6不兼容?

  18. 18

    如何在 Visual Studio Team Services (VSTS) 中构建 ASP.NET Core 2 RC2 项目?

  19. 19

    无法让ConfigurationBuilder从ASP.NET Core 1.0 RC2的xunit类库中的appsettings.json中读取

  20. 20

    无法让ConfigurationBuilder从ASP.NET Core 1.0 RC2的xunit类库中的appsettings.json中读取

  21. 21

    将Asp.Net Core RC1迁移到RC2后的问题

  22. 22

    Razor页面在运行时无法在ASP.NET Core RC2中看到引用的类库

  23. 23

    如何在ASP.NET Core RC2应用程序中手动重新加载IOptions

  24. 24

    如何在ASP.NET Core 1.0 RC2中将实例注册到ServiceCollection

  25. 25

    在ASP.NET Core RC2中使用AddAuthentication时的模棱两可的调用

  26. 26

    如何在ASP.NET Core RC2中获取控制器的自定义属性

  27. 27

    Razor页面在运行时无法在ASP.NET Core RC2中看到引用的类库

  28. 28

    在ASP.NET Core应用程序(RC2)中使用net451库

  29. 29

    在ASP Core 1.0 RC2中无法远程触发

热门标签

归档