Route using only the ID - #168
Conversation
julietdaniel
left a comment
There was a problem hiding this comment.
Looks good. This improves our URLs as UI and makes a lot more sense for routing. Clean use of RedirectPermanent to send an HTTP 301 status code.
| if (Post == null) | ||
| { | ||
| RedirectToPage("/Index"); | ||
| return RedirectToPage("/Index"); |
There was a problem hiding this comment.
Seems like this should return NotFound() if the post didn't exist.
There was a problem hiding this comment.
I tried using NotFound() but it just leads to a blank page without any indication that the post was not found.
|
|
||
| if (slug != Post.Slug) | ||
| { | ||
| return RedirectPermanent($"/Post/{Post.Id}/{Post.Slug}"); |
There was a problem hiding this comment.
Shouldn't an error or exception be thrown if the slug is not correct?
There was a problem hiding this comment.
We just want to redirect because getting the post does not depend on the slug. Also using a redirect helps with when the slug is updated because external links that use the old slug will have a "moved permanently" attached to them so people will not lose SEO on their posts.
|
If this pull request works well, it would solve this issue:Fail to open post encoded by Unicode |
Addresses #127 and #164
Redirects to a URL with the correct slug and returns a 301 Moved Permanently status for SEO purposes.