我想實現一個StackOverflow
類型的URL重定向通過我的網站。 例如實現StackOverflow類型的URL重定向
當您在瀏覽器中輸入https://stackoverflow.com/questions/11227809/
時,它會自動將您重定向到https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array
。
即使您輸入廢品價值代替標題,例如https://stackoverflow.com/questions/11227809/askl;fl;aksf
,它也會將您重定向到正確的郵政編號11227809
。
這是哪種類型的重定向?那是一個301
我知道,但我怎麼能實現這一點使用.Net MVC?
我在這裏看到過一個非MVC解決方案Here但是需要一個基於MVC的解決方案。 Thankyou。
My Route:
routes.MapRoute("QuestionUrlDetermine", "{qId}/{questionTitle}", new { controller = "Home", action = "QuestionUrlDetermine", questionTitle = UrlParameter.Optional }, new { qId = @"^\d{1,3}$" });
Action:
public ActionResult QuestionUrlDetermine (int qId)
{
…
return new RedirectResult(string.Format("/{0}/{1}", qId, questionTitle));
}
我無法找到原來的答案,但這是相似的: http://stackoverflow.com/questions/18784979/mvc-routing-changing-routes –
我已更新我的問題與代碼請檢查。 – Maven
類似的帖子:http://stackoverflow.com/questions/16248732/mvc-4-creating-slug-type-url – shakib