可以像这样在ASP.NET Core中制作SEO友好的网址 [英] Is is possible to make SEO friendly Url's in ASP.NET Core like this one

查看:66
本文介绍了可以像这样在ASP.NET Core中制作SEO友好的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问你们是否有可能为我的项目/{action}/{title}做这样的路由?

I wanted to ask you guys if is it possible, to make some routing like this for my project /{action}/{title}?

我想知道是否可行,这个URL是否也必须是主键?由于没有传递ID来知道这是哪篇博客文章.

I was wondering if that is possible, does this url has to be a primary key too? Since there is no ID passed to know which blog post is this.

谢谢.

推荐答案

您可以使用属性路由很容易地做到这一点:

You can do this quite easily with attribute routing:

[Route("blogs")]
public class BlogController
{
    [AcceptVerbs("GET", "HEAD", Route = "{slug}")]
    public IActionResult View(string slug)
    {
    }
}

这会将所有对/blogs/whatever的请求映射到该操作,并将slug设置为"/blogs/"之后的值.

This maps all requests to /blogs/whatever to that action, and sets slug to the value after "/blogs/".

这篇关于可以像这样在ASP.NET Core中制作SEO友好的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆