Adding ID and title to URL slugs in ASP.NET MVC

后端 未结 5 883
甜味超标
甜味超标 2020-12-04 07:34

How do you redirect a request in ASP.NET MVC to its correct canonical version if part of the URL is missing?

Using Stack Overflow as an example, the site adds the qu

5条回答
  •  旧巷少年郎
    2020-12-04 07:56

    While I don't know any specifics of how StackOverflow manage it, here's an overview of how you could do it

    • Retrieve the question from the database using the ID
    • Convert the stored question title into a URL compatible slug
    • If the converted title slug does not match the slug passed in the URL then redirect using the converted title slug.

    This ensures the URL is always the correct one and avoids possible embarrassing fake URLs

提交回复
热议问题