在学习MVC6中区域处理的故事时,我keep coming across blog posts有 area:exists
在路线模式中,但无论我如何努力搜索,我都无法在任何 Microsoft 文档中找到有关此内容的任何内容,而且我找到的博客文章都没有解释它在做什么或提到这些信息的来源从。
这个约束在哪里解释,内置路径模式和约束的全面的、最新的、规范的文档在哪里?作为记录,我知道 this页面,但它的结构更像是教程而不是规范引用。
如果来自 Microsoft 的任何人正在阅读本文,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
所以我想这意味着约束只是确保捕获的值是非空的。我仍然不知道该信息的规范来源在哪里。
最佳答案
由于 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);
}
关于asp.net - ASP.NET MVC5+ 中 "exists"路由约束的文档在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32294527/