Stack Overflow Question Routing

后端 未结 3 1869
北海茫月
北海茫月 2020-12-11 09:01

If you review a SO question URL you will see that an ID and a \"SLUG\" are passed to the Questions controller: https://stackoverflow.com/questions/676934/what-do-you-need-to

相关标签:
3条回答
  • 2020-12-11 09:11

    You don't need to use the slug at all. It's probably just there for human readability and search engine optimization. You can ignore it when routing and just work up to the ID.

    For instance, click here:

    Stack Overflow Question Routing

    0 讨论(0)
  • 2020-12-11 09:13

    The slug is there for search engines to catalog the resource/page. It's not used in the route at all as part of the arguments passed to the database to retrieve the requested post.

    The ID is the important part.

    So in your code, the SlugConstraint is not required and the value of the slug argument is ignored in the Details action.

    This behavior is what SO do and what you can do, if u wish to copy SO.

    0 讨论(0)
  • 2020-12-11 09:21

    The "route" can be anything the router can be configured to handle. The dynamic parts of the "route" are then passed to the landing/target page and retrieved via the RouteValue() method (in ASP.NET Routing). What you do with those values on the target page is entirely up to you. Use them or ignore them.

    So the ID (in your example) is the key and the rest (the slug) is just there for human readability and SEO.

    0 讨论(0)
提交回复
热议问题