【问题标题】:asp.net razor iis rewrite all requests to a fileasp.net razor iis 将所有请求重写到文件
【发布时间】:2017-06-01 15:49:34
【问题描述】:

这可能以前被问过,但到目前为止我还没有找到正确的搜索词。

我正在使用 IIS8 我有一个名为 Index.cshtml 的文件,其中包含我的页面逻辑 - 从数据库中检索页面内容。

因此,www.mysite.com/Index/mypage 的 URL 使用 mypage' 作为参数可以正常工作。 但是,我正在尝试在 web.config 中创建重写规则,以便我可以将 URL 设为 www.mysite.com/mypage 等。

另外,我希望根 www.mysite.com/ 重写为 www.mysite.com/Index/home

我已经尝试了很多东西,但到目前为止都不起作用 - 我将它发送到添加许多 /Index/Index/index... 的循环中,或者只是找不到页面。

非常感谢您的帮助

【问题讨论】:

    标签: asp.net razor url-rewriting iis-8


    【解决方案1】:

    好的,答案是改用路由,参考http://www.mikesdotnetting.com/article/187/more-flexible-routing-for-asp-net-web-pages

    将以下内容添加到我的 _AppStart.cshtml 中

    RouteTable.Routes.Ignore("sitemap.xml"); RouteTable.Routes.MapWebPageRoute("{cat}/{article}/{tag}/{page}", "~/Index.cshtml", new { cat = "", article = "", tag = "", page = "" });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-03
      • 2010-10-19
      • 2015-06-08
      • 2018-11-29
      • 1970-01-01
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多