我正在尝试将此示例RouteBase实现转换为与MVC 6一起使用.我已经通过遵循路由项目中的示例来解决大部分问题,但是我正在了解如何Task从方法返回异步.我真的不在乎它是否实际上是异步的(为任何可以提供答案的人欢呼),现在我只想让它运转起来.
我有传出的路线功能(ActionLink当我输入路线值时,意味着工作正常).问题在于RouteAsync方法.
public Task RouteAsync(RouteContext context)
{
var requestPath = context.HttpContext.Request.Path.Value;
if (!string.IsNullOrEmpty(requestPath) && requestPath[0] == '/')
{
// Trim the leading slash
requestPath = requestPath.Substring(1);
}
// Get the page that matches.
var page = GetPageList()
.Where(x => x.VirtualPath.Equals(requestPath))
.FirstOrDefault();
// If we got back a null value set, that means the URI did not match
if (page != null)
{
var routeData = new RouteData();
// This …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc asp.net-mvc-routing asp.net-core-mvc asp.net-core
我正在尝试建立自己的小cms.我创建了一个抽象的pageBase类,它由Static,Reviews,Articles,News继承.每个都有自己的控制器方法.
我的问题是我需要允许管理员定义自己的自定义路径级别.例如news\local\mynewdog或Articles\events\conventions\mycon.所以我想要一种传递字符串数组并设置自定义路由的方法.
c# asp.net-mvc url-routing asp.net-mvc-routing custom-routes
在我的网站上,我有这种网址:
https://www.mywebsite.com/View/Index/{MongoDbId}
Run Code Online (Sandbox Code Playgroud)
Controller返回包含产品详细信息的View.
我的产品类DTO(只是重要的领域)
public class ProductDto
{
public string Id {get; set;}
public string Name {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
在这一刻,我有一个名为View的控制器和一个处理请求的Index方法,但我希望有这样的东西:
https://www.mywebsite.com/v/56b8b8801561e80c245a165c/amazing-product-name
Run Code Online (Sandbox Code Playgroud)
实现这个的最佳方法是什么?
我已经阅读过关于ASP.NET Core (GitHub上的官方项目)的路由,但我不太清楚如何做.
谢谢!!