在ASP.NET URL重写5 [英] URL rewrite in ASP.NET 5

查看:170
本文介绍了在ASP.NET URL重写5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET 5所在的整个文件夹结构发生变化,并在web.config被替换(相对于previous ASP.NET版本)。我做的客户端使用angularJS路由和我有这样的路线:

I'm using ASP.NET 5 where the entire folder structure is changed and the web.config is replaced (compared to previous ASP.NET versions). I'm doing client side routing using angularJS and I have this route:

.when('/movies/add', {
            templateUrl: '/Views/add.html',
            controller: 'MoviesAddController'
        })

一切工作的渴望,我开始我的index.html,然后点击一个链接到/电影的/补充。如果我使用/电影重新加载页面/ URL添加的服务器给我一个404按照本教程中我应该在web.config中做一个重写,像这样的:

Everything works as longs as I start on my index.html and click on a link to /movies/add. If I reload the page using the /movies/add URL, the server gives me a 404. According to this tutorial I should do a rewrite in web.config, like this:

<!-- from http://stackoverflow.com/questions/25916851/wrapping-staticfilemiddleware-to-redirect-404-errors -->

<configuration>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
  <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>
</system.webServer>
</configuration>  

我使用IIS防爆$ P $ 10.0 PSS(在Windows 10 preVIEW)。据我所知,在web.config中的部分应该在ASP.NET 5仍然存在配置IIS,但我没有得到任何与此结果。
我是否需要使用IIS防爆preSS做不同的事情?是否有ASP.NET提供5另一个更普遍,如何解决?

I am using IIS Express 10.0 (in Windows 10 preview). I understand that the part in web.config should still exist in ASP.NET 5 to configure IIS but I don't get any result from this. Do I need to do something different using IIS Express? Is there another, more general, solution provided in ASP.NET 5?

谢谢!

推荐答案

的web.config 仍然支持,但是它应该进入 wwwroot文件文件夹中。您可能缺少URL重写模块为IIS。

web.config is still supported but it should go into wwwroot folder. You may be missing Url Rewrite module for IIS.

另外,你可以写一个自定义OWIN中间件支持HTML5的路由模式。

Alternatively, you can write a custom OWIN middleware to support html5 routing mode.

一个例子来看看这个:
<一href=\"http://geekswithblogs.net/shaunxu/archive/2014/06/10/host-angularjs-html5mode-in-asp.net-vnext.aspx\">http://geekswithblogs.net/shaunxu/archive/2014/06/10/host-angularjs-html5mode-in-asp.net-vnext.aspx

这篇关于在ASP.NET URL重写5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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