在ASP .NET MVC 3中重写URL - 在链接中添加*.html后缀

dra*_*fly 0 asp.net asp.net-mvc iis-7 url-rewriting asp.net-mvc-3

我正在创建简单的应用程序,某种投资组合.我听说在链接中有一个*.html后缀更好,因为当谷歌索引时它会让我获得更好的SEO结果...

无论如何,有没有办法修改默认路由/重写网址,以便我的链接看起来像这样(我使用的波兰语字对我的访问者来说是可读的):

domain.pl/index.html
domain.pl/kontakt.html
domain.pl/oferta.html
domain.pl/sklepy.html
Run Code Online (Sandbox Code Playgroud)

这些链接被转换为一个控制器(如HomeController),但{0} .html链接中的{0}将被用作动作名称?或者甚至更好,我想将{0}从Url映射到英文动作名称,如:

index.html = index action
kontakt.html = contact action
oferta.html = offer action
sklepy.html = shops action
Run Code Online (Sandbox Code Playgroud)

arc*_*hil 8

不确定更好的搜索引擎优化结果,但添加后缀很简单

        routes.MapRoute(
            "Default",
            "{action}.html",
            new { controller = "Home", action = "Index" }
        );
Run Code Online (Sandbox Code Playgroud)

只需将.html后缀添加到action参数占位符即可.

对于翻译,您可以使用 ActionNameAttribute

    [ActionName("kontakt")]
    public ActionResult Contact()
    {
        return View();
    }
Run Code Online (Sandbox Code Playgroud)

将上述两个代码组合在一起,就可以domain.pl/kontakt.html映射到Home/Contact操作.