2014-01-08 20 views
2

我有一個路徑建立像返回一個特定的博客條目網址 例如用戶可以輸入上述網址,但是當他得到的頁面返回的URL必須是這樣的:訪問 時,它看起來像這樣</p> <pre><code>www.mywebsite.com/100 </code></pre> <p>但是我想在返回的頁面時,我還添加了博客標題添加字符串到請求的URL

www.mywebsite.com/100/My-Blog-Title 

就像它發生在這裏Stakoverflow說: 我進入這個網址

http://stackoverflow.com/questions/11227809/ 

並經過請求收到的URL如下所示:

http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array 

在我的MVC項目中如何實現這個功能?任何人都可以請幫忙。

請同時評論SEO的友善程度,同時建議您的優先方法。

Thankyou

+1

看看這個鏈接:http://stackoverflow.com/questions/25259/how-does-stack-overflow-generate-its-seo-friendly-urls/25486#25486 – Lin

回答

0

您可以使用JavaScript。

返回存儲在某個JavaScript變量中的博客標題。

var blogTitle = "My-Blog-Title" 

閱讀博客的標題和閱讀本link更改URL重定向沒有。

0

如果打開Chrome開發工具,網絡選項卡,加載了地址(僅ID),這個問題(http://stackoverflow.com/questions/21005768/),你會看到你回來一個一個HTTP 301響應 - 永久重定向到友好url(http://stackoverflow.com/questions/21005768/add-string-to-the-requested-url/)。

要使用此迴應在ASP.NET MVC你會做類似如下:

public ActionResult GetThingy(int id) 
{ 
    var title = GetTitle(id); 
    return RedirectPermanent(Url.Action("GetThingy", new { id = id, title = title}); 
} 

會重定向到另一個動作,如控制器上:

public ActionResult GetThingy(int id, string title) 
{ 
    //do your thing here 
} 
相關問題