【问题标题】:When my SEO text slug in the URL ends with a dot symbol, I get a 404 error当 URL 中的 SEO 文本块以点符号结尾时,我收到 404 错误
【发布时间】:2012-07-14 20:32:14
【问题描述】:

很奇怪!

这是自定义路线:

        routes.MapRoute(
            "Dota2-News-Details", // Route name
            "dota2-news/{id}/{slug}", // URL with parameters
            new { controller = "Dota2News", action = "Detail", slug = "", id = UrlParameter.Optional } // Parameter defaults
        );

工作链接:

http://localhost:20099/dota2-news/3/Some-random-post
http://localhost:20099/dota2-news/5/Another-random-post
http://localhost:20099/dota2-news/14/New-delicious-items

无效链接:

http://localhost:20099/dota2-news/4/The-Dark-Moon-comes.
http://localhost:20099/dota2-news/11/Bwa-ha-welcome.

一时兴起,我进入数据库并修改了 SEOTextSlug 以从值中删除最后的 . 符号。正如预期的那样,它现在可以正常工作。不过我很困惑,我认为 URL 可以以 . 符号结尾。

这是我的控制器:

public ActionResult Detail(int id, string slug)
{
    var viewModel = new OfficialNewsModel();
    var news = _officialNewsRepository.FindById(id);

    if (news.SEOTextSlug != slug)
    {
        return RedirectToAction("Detail", "Dota2News", new { id = news.OfficialNewsId, slug = news.SEOTextSlug });
    }

    viewModel = Mapper.Map<OfficialNew, OfficialNewsModel>(news);
    return View(viewModel);
}

我的问题:

为什么尾随 . 符号会破坏应用程序? URL 中不能有 doy 符号?

“/”应用程序中的服务器错误。无法找到该资源。 描述:HTTP 404。您正在寻找的资源(或其之一 依赖项)可能已被删除,名称已更改,或者是 暂时不可用。请查看以下 URL 并制作 确保拼写正确。

请求的 URL:/dota2-news/1/In-defense-of-the-Temple。

版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.225

【问题讨论】:

    标签: c# asp.net-mvc-3 routes


    【解决方案1】:

    URL 中不能有 doy 符号?

    可以。虽然开箱即用,但最终并非如此。

    因此,允许它在您的 web.config&lt;system.web&gt; 部分)中添加以下内容:

    <httpRuntime relaxedUrlToFileSystemMapping="true" />
    

    Haacked blogged 关于它。 Hanselman also。如果您是 .NET 开发人员并且还没有订阅这 2 个博客并每天阅读它们,您可能会错过很多有用的东西。

    【讨论】:

      猜你喜欢
      • 2018-04-04
      • 2017-03-12
      • 2018-04-16
      • 2014-08-19
      • 2019-01-24
      • 1970-01-01
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多