ASP.NET MVC5 +中“存在”路由约束的文档在哪里?

时间:2015-08-30 08:08:47

标签: asp.net asp.net-mvc asp.net-mvc-5 asp.net-mvc-routing

在了解MVC6中的区域处理故事时,我keep coming across blog posts在路由模式中有area:exists但是无论我搜索多么困难,我都无法在任何Microsoft文档中找到任何关于此内容的内容,而且我发现的所有博客文章都没有解释它正在做什么或提到那些信息的来源。

解释了这种约束的位置,以及内置路由模式和约束的全面,最新,规范文档在哪里?为了记录,我知道this页面,但它的结构更像是教程而不是规范参考。

如果微软的任何人正在阅读此内容,http://www.asp.net/mvc/overview/api-reference会导致一个页面旁边没有任何信息和一个未同步的目录,我找不到我想要的内容。并且您的RouteAttribute类引用没有指向任何解释url模式应该是什么样的内容的链接。

修改

经过深入挖掘,我发现了这个: https://github.com/aspnet/Mvc/blob/48bfdceea6d243c5ec8d6e00f450f8fe7cce59f7/src/Microsoft.AspNet.Mvc.Core/MvcCoreRouteOptionsSetup.cs#L26

所以它与KnownRouteValueConstraint有关,这导致我: https://github.com/aspnet/Mvc/blob/e0b8532735997c439e11fff68dd342d5af59f05f/src/Microsoft.AspNet.Mvc.Core/KnownRouteValueConstraint.cs#L26-L40

所以我猜这意味着约束只是确保捕获的值是非空的。我仍然不知道该信息的规范来源在哪里。

1 个答案:

答案 0 :(得分:2)

由于ASP.NET 5 / MVC 6是not yet officially released,并且目前API尚未稳定,因此文档尚未完成并不令人惊讶。

请注意,ASP.NET vNext是开源的,因此在缺少文档的地方,您可以随时查看测试以尝试确定要执行的操作。 Here are some测试内联约束area:exists

[Fact]
public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectAction()
{
    // Arrange
    var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
    var client = server.CreateClient();

    // Act
    var response = await client.GetAsync("http://localhost/area-exists/Users");

    // Assert
    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
    var returnValue = await response.Content.ReadAsStringAsync();
    Assert.Equal("Users.Index", returnValue);
}

[Fact]
public async Task RoutingToANonExistantArea_WithoutExistConstraint_RoutesToIncorrectAction()
{
    // Arrange
    var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
    var client = server.CreateClient();

    // Act
    var response = await client.GetAsync("http://localhost/area-withoutexists/Users");

    // Assert
    var exception = response.GetServerException();
    Assert.Equal("The view 'Index' was not found." +
                 " The following locations were searched:__/Areas/Users/Views/Home/Index.cshtml__" +
                 "/Areas/Users/Views/Shared/Index.cshtml__/Views/Shared/Index.cshtml.",
                 exception.ExceptionMessage);
}