asp.net-mvc - 创建类似于Stack Overflow的短固定链接“这个问题的短暂固定链接”

我想我可能已经明白这是怎么回事了,但我想确定一下。
我正在为新的ASP.NET MVC应用程序定义路由。我想创建与Stack Overflow的short permalink类似的short permalink来解决这个问题:
Create short permalinks similar to Stack Overflow's "short permalink to this question"
堆栈溢出用于此永久链接行为的路由和控制器机制是什么?
讨论堆栈溢出问题路由的其他问题:
How can I create a friendly URL in ASP.NET MVC?
How do you include a webpage title as part of a webpage URL?
Creating search engine friendly URL's in ASP.NET MVC


最佳答案:

我相信堆栈溢出路由的设置与此类似:

routes.MapRoute("question-permalink", "q/{questionId}/{userId}", 
    new { controller = "PermaLinkController",
        action = "Question", userId = UrlParameter.Optional },
    new { questionId = "[0-9]+", userId = "[0-9]+" });

基于指向问题当前位置的302 Found:我假设PermaLink控制器的问题操作如下所示:
public class PermaLinkController : Controller
{
    public Question (int questionId, int? userId)
    {
        // do work to record userId that shared link
        // ...
        // now redirect
        Response.RedirectToRoute("question", new { questionId = questionId });
    }
}