1. <tfoot id='aPpmB'></tfoot>
    2. <small id='aPpmB'></small><noframes id='aPpmB'>

      <i id='aPpmB'><tr id='aPpmB'><dt id='aPpmB'><q id='aPpmB'><span id='aPpmB'><b id='aPpmB'><form id='aPpmB'><ins id='aPpmB'></ins><ul id='aPpmB'></ul><sub id='aPpmB'></sub></form><legend id='aPpmB'></legend><bdo id='aPpmB'><pre id='aPpmB'><center id='aPpmB'></center></pre></bdo></b><th id='aPpmB'></th></span></q></dt></tr></i><div id='aPpmB'><tfoot id='aPpmB'></tfoot><dl id='aPpmB'><fieldset id='aPpmB'></fieldset></dl></div>

        <legend id='aPpmB'><style id='aPpmB'><dir id='aPpmB'><q id='aPpmB'></q></dir></style></legend>
        • <bdo id='aPpmB'></bdo><ul id='aPpmB'></ul>

        ASP.net core MVC 捕获所有路由服务静态文件

        ASP.net core MVC catch all route serve static file(ASP.net core MVC 捕获所有路由服务静态文件)
          <tbody id='rBe6M'></tbody>

        <legend id='rBe6M'><style id='rBe6M'><dir id='rBe6M'><q id='rBe6M'></q></dir></style></legend>

              <small id='rBe6M'></small><noframes id='rBe6M'>

                <i id='rBe6M'><tr id='rBe6M'><dt id='rBe6M'><q id='rBe6M'><span id='rBe6M'><b id='rBe6M'><form id='rBe6M'><ins id='rBe6M'></ins><ul id='rBe6M'></ul><sub id='rBe6M'></sub></form><legend id='rBe6M'></legend><bdo id='rBe6M'><pre id='rBe6M'><center id='rBe6M'></center></pre></bdo></b><th id='rBe6M'></th></span></q></dt></tr></i><div id='rBe6M'><tfoot id='rBe6M'></tfoot><dl id='rBe6M'><fieldset id='rBe6M'></fieldset></dl></div>
                • <bdo id='rBe6M'></bdo><ul id='rBe6M'></ul>
                  <tfoot id='rBe6M'></tfoot>

                  本文介绍了ASP.net core MVC 捕获所有路由服务静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法让 catch all 路由服务于静态文件?

                  Is there a way to make a catch all route serve a static file?

                  看这个http://blog.nbellocam.me/2016/03/21/routing-angular-2-asp-net-core/

                  我基本上想要这样的东西:

                  I basically want something like this:

                          app.UseMvc(routes =>
                          {
                              routes.MapRoute("default", "{controller}/{action=Index}");
                  
                              routes.MapRoute("spa", "{*url}"); // This should serve SPA index.html
                          });
                  

                  所以任何与 MVC 控制器不匹配的路由都会提供 wwwroot/index.html

                  So any route that doesn't match an MVC controller will serve up wwwroot/index.html

                  推荐答案

                  如果您已经处于路由阶段,那么您已经过了在管道中提供静态文件的阶段.您的初创公司将如下所示:

                  If you're already in the routing stage, you've gone past the point where static files are served in the pipeline. Your startup will look something like this:

                  app.UseStaticFiles();
                  
                  ...
                  
                  app.UseMvc(...);
                  

                  这里的顺序很重要.因此,您的应用将首先查找静态文件,这从性能的角度来看是有意义的 - 如果您只想丢弃静态文件,则无需运行 MVC 管道.

                  The order here is important. So your app will look for static files first, which makes sense from a performance standpoint - no need to run through MVC pipeline if you just want to throw out a static file.

                  您可以创建一个包罗万象的控制器操作,该操作将返回文件的内容.例如(窃取您评论中的代码):

                  You can create a catch-all controller action that will return the content of the file instead. For example (stealing the code in your comment):

                  public IActionResult Spa()
                  {
                      return File("~/index.html", "text/html");
                  }
                  

                  这篇关于ASP.net core MVC 捕获所有路由服务静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)

                  1. <i id='XKhuw'><tr id='XKhuw'><dt id='XKhuw'><q id='XKhuw'><span id='XKhuw'><b id='XKhuw'><form id='XKhuw'><ins id='XKhuw'></ins><ul id='XKhuw'></ul><sub id='XKhuw'></sub></form><legend id='XKhuw'></legend><bdo id='XKhuw'><pre id='XKhuw'><center id='XKhuw'></center></pre></bdo></b><th id='XKhuw'></th></span></q></dt></tr></i><div id='XKhuw'><tfoot id='XKhuw'></tfoot><dl id='XKhuw'><fieldset id='XKhuw'></fieldset></dl></div>

                      • <legend id='XKhuw'><style id='XKhuw'><dir id='XKhuw'><q id='XKhuw'></q></dir></style></legend>

                        <tfoot id='XKhuw'></tfoot>
                          <tbody id='XKhuw'></tbody>

                        <small id='XKhuw'></small><noframes id='XKhuw'>

                        • <bdo id='XKhuw'></bdo><ul id='XKhuw'></ul>