Skip to content
This repository was archived by the owner on May 19, 2024. It is now read-only.

Route using only the ID - #168

Open
umaslakshmi wants to merge 6 commits into
masterfrom
Routing-Using-Id
Open

Route using only the ID#168
umaslakshmi wants to merge 6 commits into
masterfrom
Routing-Using-Id

Conversation

@umaslakshmi

Copy link
Copy Markdown
Contributor

Addresses #127 and #164

Redirects to a URL with the correct slug and returns a 301 Moved Permanently status for SEO purposes.

@julietdaniel julietdaniel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should return NotFound() if the post didn't exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't an error or exception be thrown if the slug is not correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MFunction96

MFunction96 commented Oct 16, 2017

Copy link
Copy Markdown

If this pull request works well, it would solve this issue:Fail to open post encoded by Unicode
However, I check the entire project. I think there are a lot of routes required to fix, such as BlogTemplate/Pages/Index.cshtml line 21.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants