当在URL我的SEO文本塞以点符号结束后,我得到一个404错误 [英] When my SEO text slug in the URL ends with a dot symbol, I get a 404 error

查看:123
本文介绍了当在URL我的SEO文本塞以点符号结束后,我得到一个404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很奇怪!

下面是自定义路线:

  routes.MapRoute(
            DOTA2 - 新闻 - 详细信息,//路线名称
            DOTA2新闻/ {ID} / {}塞,// URL带参数
            新{控制器=Dota2News,行动=详细信息,蛞蝓=,ID = UrlParameter.Optional} //参数默认
        );

工作链接:

 的http://本地主机:20099 / DOTA2新闻/ 3 /一些随机的,后
HTTP://本地主机:20099 / DOTA2新闻/ 5 /另一个随机员额
HTTP://本地主机:20099 / DOTA2新闻/ 14 /新好吃项

非工作链接:

 的http://本地主机:20099 / DOTA2新闻/ 4 /最暗月亮来了。
HTTP://本地主机:20099 / DOTA2新闻/ 11 / BWA-HA-欢迎。

在一个突发奇想,我在数据库中去,并修改了SEOTextSlug删除最后一个从符号的价值。正如预期的那样,现在正常工作。我很困惑,虽然,我想的URL可以用一个符号结束。

下面是我的控制器:

 公众的ActionResult详细(INT ID,字符串蛞蝓)
{
    VAR视图模型=新OfficialNewsModel();
    VAR新闻= _officialNewsRepository.FindById(ID);    如果(news.SEOTextSlug!=蛞蝓)
    {
        返回RedirectToAction(详细信息,Dota2News,新{ID = news.OfficialNewsId,蛞蝓= news.SEOTextSlug});
    }    视图模型= Mapper.Map< OfficialNew,OfficialNewsModel>(新闻);
    返回视图(视图模型);
}

我的问题:

为什么尾随符号,打破了应用程序?一个URL不能有DOY符号随时随地呢?


  

在'/'应用程序的服务器错误。资源无法找到。
  说明:HTTP 404。您正在寻找(或一个资源的
  依赖)可能已被删除,更名,或
  暂时不可用。请检查以下URL并
  确认其拼写正确。


  
  

请求的URL:/ DOTA2新闻/ 1 /在防御的最寺


  
  

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



解决方案

  

一个URL不能有DOY符号随时随地呢?


就可以了。而不是在最后阶段外的开箱。

因此​​,要允许它下面的添加到您的的web.config <&的System.Web GT; 章节)

 <的httpRuntime relaxedUrlToFileSystemMapping =真/>

Haacked博客一下吧。 <一href=\"http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx\"相对=nofollow> Hanselman的也的。如果你是一个.NET开发人员,还没有订阅的2博客和每天都在阅读他们,你可能会错过很多有用的东西。

Quite strange!

Here is the custom route:

        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
        );

Working links:

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

Non-working links:

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

On a whim, I went in the database and modified the SEOTextSlug to remove the final . symbol from the value. As expected, it now works properly. I'm confused though, I thought URL's could end with a . symbol.

Here's my Controller:

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);
}

My question:

Why does the trailing . symbol, break the app? A URL can't have a doy symbol anywhere in it?

Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /dota2-news/1/In-defense-of-the-Temple.

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

解决方案

A URL can't have a doy symbol anywhere in it?

It can. Not at the end though out-of-the-box.

So to allow it add the following to your web.config (<system.web> section):

<httpRuntime relaxedUrlToFileSystemMapping="true" />

Haacked blogged about it. Hanselman also. If you are a .NET developer and haven't yet subscribed to those 2 blogs and read them on a daily basis you will probably miss lots of useful things.

这篇关于当在URL我的SEO文本塞以点符号结束后,我得到一个404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆