asp.net mvc的托管与html5mode和路由角应用 [英] asp.net mvc hosting angular app with html5mode and routing

查看:115
本文介绍了asp.net mvc的托管与html5mode和路由角应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我主持asp.net的MVC 5内的angularjs并使用 html5mode(真)在我的角度应用在摆脱所有的井号该URL。
一切都很正常,但我目前的设置,看起来像这样:

Alright, so I am hosting an angularjs inside asp.net mvc 5 and are using the html5mode(true) in my angular app to get rid of all hash signs in the url. Everything works great, however, with my current setup that looks like this:

RouteConfig.cs:

RouteConfig.cs:

        routes.MapRoute(
            name: "Default",
            url: "app/{angular}",
            defaults: new { controller = "Ng", action = "Index", angular= UrlParameter.Optional }
        );

所以,当我浏览到的 的http:// URL /应用/ myangularroute 我的纳克/指数行动返回包含NG-View容器,角应用现在是活动的,并与所提供的路线工作的看法

So that when I navigate to http://url/app/myangularroute my Ng/Index action returns the view which contains the ng-view container and the angular app is now active and working with the route provided

现在,我的问题在这里,当我浏览到的 的http:// URL /应用/ 返回listning不允许一个目录错误我无法理解。作为角参数设置为可选不应退还我的索引操作?

Now, my problem here is, when I navigate to http://url/app/ it returns a dir listning not allowed error which I cannot understand. Shouldn't my index action be returned as the angular parameter is set to optional?

和可我莫名其妙地避免应用程序完全,仍然让我的角速度的应用程序工作?我已经尝试了一些重写规则,但是这给了我很多的错误,因为我利用的MVC捆绑和缩小功能。

And can I somehow avoid the "app" completely and still get my angular app to work? I have tried some rewrite rules but that gives me alot of errors because I am making use of the mvc bundling and minification functionality.

我可以与URL生活是它目前是,但无需提供可选的参数,如格式的 的http:// URL /应用/

I could live with the url being the format it currently is but without the need to provide the optional parameter, like http://url/app/

此外,它只是一个角度应用程序,比index.cshtml包装没有其他的MVC视图。

Also, it's only an angular app, no other mvc view than the index.cshtml wrapper.

<一个href=\"http://stackoverflow.com/questions/21095835/using-html5mode-for-navigating-with-angularjs-at-non-root-url\">This家伙似乎得到它的工作,但我无法看到他的MVC路线

推荐答案

试着在你的web.config添加此 sytem.webserver 设置。

Try adding this in your web.config sytem.webserver settings.

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
<system.webServer>

修改

试着改变你的RouteConfig.cs,像这样的:

Try changing your RouteConfig.cs, like this:

    routes.MapRoute(
        name: "Default",
        url: "app/{*.}",
        defaults: new { controller = "Ng", action = "Index" }
    );

EDIT2:

我已经完全forgoten这个问题,但现在我才意识到,也许,问题是你有没有配置IIS服务器与Html5Mode工作,看看这个:<一href=\"https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode\">https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

I had completely forgoten about this question, but now I just realized that maybe the problem is that you haven't configured your IIS Server to work with Html5Mode, have a look at this: https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

Concretelly这一部分:

Concretelly this part:

Azure的IIS重写:

<system.webServer>
  <rewrite>
    <rules> 
      <rule name="Main Rule" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                                 
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="/" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

我希望这会有所帮助。

I hope that this helps.

这篇关于asp.net mvc的托管与html5mode和路由角应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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