此外,它只是一个有角度的应用程序,除了 index.cshtml 包装器之外没有其他 mvc 视图.这家伙似乎让它起作用了,但我看不到他的 mvc 路线 解决方案 尝试将其添加到您的 web.config sytem.webserver 设置中.<modules runAllManagedModulesForAllRequests="true"/><system.webServer>编辑:尝试更改您的 RouteConfig.cs,如下所示: routes.MapRoute(名称:默认",url: "app/{*.}",默认值:new { controller = "Ng", action = "Index" });我完全忘记了这个问题,但现在我才意识到问题可能是您尚未将 IIS 服务器配置为使用 Html5Mode,请看一下:https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode具体来说这部分:Azure IIS 重写:<重写><规则><规则名称="主规则" stopProcessing="true"><match url=".*"/><conditions logicalGrouping="MatchAll"><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></条件><action type="重写" url="/"/></规则></规则></rewrite></system.webServer>我希望这会有所帮助.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: routes.MapRoute( name: "Default", url: "app/{angular}", defaults: new { controller = "Ng", action = "Index", angular= UrlParameter.Optional } );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 providedNow, 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?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.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/Also, it's only an angular app, no other mvc view than the index.cshtml wrapper.This guy seems to get it to work, but I can't see his mvc routes 解决方案 Try adding this in your web.config sytem.webserver settings.<system.webServer> <modules runAllManagedModulesForAllRequests="true"/><system.webServer>EDIT:Try changing your RouteConfig.cs, like this: routes.MapRoute( name: "Default", url: "app/{*.}", defaults: new { controller = "Ng", action = "Index" } );EDIT2: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-html5modeConcretelly this part:Azure IIS Rewrites:<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. 这篇关于带有 html5mode 和路由的 asp.net mvc 托管 angular 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!