Jos*_*sef 8 asp.net html5 routing angularjs
好吧,所以我在asp.net mvc 5中托管一个angularjs,并使用html5mode(true)我的角度应用程序来摆脱网址中的所有哈希标志.但是,一切都很好,我目前的设置如下:
RouteConfig.cs:
routes.MapRoute(
name: "Default",
url: "app/{angular}",
defaults: new { controller = "Ng", action = "Index", angular= UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
因此,当我导航到http://url/app/myangularroute我的Ng/Index操作时,返回包含ng-view容器的视图,角度应用程序现在处于活动状态并使用提供的路径
现在,我的问题是,当我导航到http://url/app/它时,返回一个dir listning不允许的错误,我无法理解.由于angular参数设置为optional,我的索引操作不应该返回吗?
我可以以某种方式完全避免"应用程序",仍然让我的角度应用程序工作?我尝试了一些重写规则,但这给了我很多错误,因为我正在使用mvc捆绑和缩小功能.
我可以使用url作为当前格式但不需要提供可选参数,例如 http://url/app/
此外,它只是一个角度应用程序,没有其他mvc视图比index.cshtml包装器.
Jos*_*sep 16
尝试在web.config sytem.webserver设置中添加此项.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<system.webServer>
Run Code Online (Sandbox Code Playgroud)
编辑:
尝试更改RouteConfig.cs,如下所示:
routes.MapRoute(
name: "Default",
url: "app/{*.}",
defaults: new { controller = "Ng", action = "Index" }
);
Run Code Online (Sandbox Code Playgroud)
EDIT2:
我完全忘记了这个问题,但现在我才意识到问题可能是你没有配置你的IIS服务器来使用Html5Mode,看看这个:https://github.com/angular-ui/ UI路由器/维基/常问,问题#如何以进行配置,您的服务器到工作与- html5mode
具体来说这部分:
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>
Run Code Online (Sandbox Code Playgroud)
我希望这个对你有用.
这是我的解决方案.我正在使用ASP.NET MVC + Web API.ASP.NET MVC总是为任何URL返回相同的HTML页面,因此AngularJS可以接管$ locationProvider.html5Mode(true);
RouteConfig.cs
routes.MapRoute(
name: "Default",
url: "{*anything}",
defaults: new
{
controller = "Home",
action = "Index",
}
);
Run Code Online (Sandbox Code Playgroud)
WebApiConfig.cs
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}/{id1}",
defaults: new
{
action = RouteParameter.Optional,
id = RouteParameter.Optional,
id1 = RouteParameter.Optional,
}
);
Run Code Online (Sandbox Code Playgroud)
HomeController.cs
public ActionResult Index()
{
return File("~/index.html", "text/html");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10243 次 |
| 最近记录: |