Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重写ASP.NET MVC 3中的Url-将*.html后缀添加到链接_Asp.net_Asp.net Mvc_Asp.net Mvc 3_Iis 7_Url Rewriting - Fatal编程技术网

重写ASP.NET MVC 3中的Url-将*.html后缀添加到链接

重写ASP.NET MVC 3中的Url-将*.html后缀添加到链接,asp.net,asp.net-mvc,asp.net-mvc-3,iis-7,url-rewriting,Asp.net,Asp.net Mvc,Asp.net Mvc 3,Iis 7,Url Rewriting,我正在创建简单的应用程序,某种类型的投资组合。我听说在链接中最好有一个*.html后缀,因为它会让我在谷歌索引时获得更好的搜索引擎优化结果 无论如何,有没有办法修改默认路由/重写url,使我的链接看起来像这样(我使用波兰语,它们对我的访问者来说是可读的): 这些链接被转换成一个控制器(比如HomeController),但是{0}.html链接中的{0}将被用作操作名?或者更好,我想将{0}从Url映射到英文动作名称,如: index.html = index action kontakt.ht

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

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

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

index.html = index action
kontakt.html = contact action
oferta.html = offer action
sklepy.html = shops action

不确定是否有更好的搜索引擎优化结果,但添加后缀非常简单

        routes.MapRoute(
            "Default",
            "{action}.html",
            new { controller = "Home", action = "Index" }
        );
只需将.html后缀添加到动作参数占位符

对于翻译,您可以使用


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

对于翻译和后缀,您可以尝试使用。 安装此软件包后,您无需在Global.asax中配置路由,控制器如下所示:

[GET("index.html")]
public ActionResult Index()
{
    return View();
}

[GET("/any/url/path/kontakt.html")]
public ActionResult Contact()
{
    return View();
}

[GET("oferta.html")]
public ActionResult Offer()
{
    return View();
}
顺便说一下,如果您想删除每个属性上重复的.html,您可以创建自己的属性来扩展GETAttribute并附加.html。如果有很多页面需要配置,这将非常有用

    [ActionName("kontakt")]
    public ActionResult Contact()
    {
        return View();
    }
[GET("index.html")]
public ActionResult Index()
{
    return View();
}

[GET("/any/url/path/kontakt.html")]
public ActionResult Contact()
{
    return View();
}

[GET("oferta.html")]
public ActionResult Offer()
{
    return View();
}