控制器动作不会调用如果URL参数为长 [英] Controller action doesn't call if URL parameter is long

查看:291
本文介绍了控制器动作不会调用如果URL参数为长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FYI:我的问题是不是 404.20在MVC 3 长的URL所以恳请不要混淆。

我有一个Asp.net MVC应用程序,其中我有一个接受一个字符串类型参数的操作方法。网址为同一可能非常长像下面。

<$p$p><$c$c>http://localhost:10537/Search/True_IsFixerUpper/True_IsNewConstruction/True_HasHorses/True_HasVirtualTour/True_HasGarage/True_IsShortSale/True_IsWaterFront/True_HasSwimmingPool/True_HasGolfCourse/True_IsWithinGatedCommunity/True_IsMobileManufacturedHome/True_IsForclosure/True_HasFireplace/True_Is55Community/True_IsWaterfrontRiver/True_IsWaterfrontBay/True_IsWaterfrontInteriorCanal/True_IsWaterfrontOcean/True_IsWaterfrontOceanAccess/True_IsWaterfrontIntracoastal/True_IsWaterfrontLake/True_HasViewOcean/True_HasViewGarden/True_HasViewGolfCourse/True_HasViewRiver/True_HasViewCanal/True_HasViewPond/True_HasViewLake/True_HasViewPool/True_HasPhotos/True_IsOpenHouse/True_IsFenced/True_IsNavigable/True_IsAttached/True_IsDetached/True_IsSemiDetached/True_IsOneStory/True_IsTwoStory/True_IsNonMls/True_IsBoatHouse/True_IsBoatSlip/True_IsDockMooring/

以上是给一个错误的 HTTP错误404.20 - 找不到

 最可能的原因:
    默认文档未配置的网站。
    URL包含一个拼写错误。
    目录浏览未启用。您可以尝试:    配置此站点默认文档。这是ASP.NET常用的Default.aspx和的index.php为PHP。
    检查浏览器URL。
    允许目录浏览,允许列出该目录的内容。

而低于网址工作正常。

<$p$p><$c$c>http://localhost:10537/Search?Query=True_IsFixerUpper/True_IsNewConstruction/True_HasHorses/True_HasVirtualTour/True_HasGarage/True_IsShortSale/True_IsWaterFront/True_HasSwimmingPool/True_HasGolfCourse/True_IsWithinGatedCommunity/True_IsMobileManufacturedHome/True_IsForclosure/True_HasFireplace/True_Is55Community/True_IsWaterfrontRiver/True_IsWaterfrontBay/True_IsWaterfrontInteriorCanal/True_IsWaterfrontOcean/True_IsWaterfrontOceanAccess/True_IsWaterfrontIntracoastal/True_IsWaterfrontLake/True_HasViewOcean/True_HasViewGarden/True_HasViewGolfCourse/True_HasViewRiver/True_HasViewCanal/True_HasViewPond/True_HasViewLake/True_HasViewPool/True_HasPhotos/True_IsOpenHouse/True_IsFenced/True_IsNavigable/True_IsAttached/True_IsDetached/True_IsSemiDetached/True_IsOneStory/True_IsTwoStory/True_IsNonMls/True_IsBoatHouse/True_IsBoatSlip/True_IsDockMooring/http://localhost:10537/Search/True_IsFixerUpper/True_IsNewConstruction/True_HasHorses/True_HasVirtualTour/True_HasGarage

控制器

 公共类SearchController:BaseController
{
        公众的ActionResult指数(字符串查询)
        {
        }
}

路线

 公共静态无效的RegisterRoutes(RouteCollection路线)
{
    routes.Ignore({}资源个.axd / {*} PATHINFO);
    routes.MapRoute(
        搜索,//路线名称
        搜索/ {*}查询,//带参数的URL
        新{控制器=搜索,行动=索引,查询= UrlParameter.Optional} //参数默认
    );    routes.MapRoute(
        默认,//路线名称
        {控制器} / {行动} / {ID},// URL带参数
        新{控制器=家,行动=索引,ID = UrlParameter.Optional} //参数默认
    );
}

可能是什么问题。


解决方案

您因为有请求太多的URL部分得到这个错误。

检查:
http://www.iis.net/learn/extensions/introduction-to-iis-ex$p$pss/iis-80-ex$p$pss-readme

                 IIS 8.0防爆preSS太多URL段返回HTTP 404.20错误。


更新:

请按照下面这个网址URL更改段计数的限制。(默认值为32)。

http://blogs.msdn.com/b/vijaysk/archive/2012/10/11/iis-8-what-s-new-website-settings.aspx

更改配置之后,url将通过段的验证计数。

现在的错误将引发约超过maxUrlLength。

您需要添加以下内容到&LT;的System.Web /&GT; 部分您的的Web.config 文件。

 &LT;的httpRuntime maxUrlLength =9999maxQueryStringLength =9999/&GT;

然后与许多领域的长期请求的URL的作品终于!!!

FYI: My question is not a duplicate of 404.20 for long url in MVC 3 so kindly do not confuse.

I have an Asp.net MVC application where I have a action method which accepts a string type parameter. URL for the same could be very long like below.

http://localhost:10537/Search/True_IsFixerUpper/True_IsNewConstruction/True_HasHorses/True_HasVirtualTour/True_HasGarage/True_IsShortSale/True_IsWaterFront/True_HasSwimmingPool/True_HasGolfCourse/True_IsWithinGatedCommunity/True_IsMobileManufacturedHome/True_IsForclosure/True_HasFireplace/True_Is55Community/True_IsWaterfrontRiver/True_IsWaterfrontBay/True_IsWaterfrontInteriorCanal/True_IsWaterfrontOcean/True_IsWaterfrontOceanAccess/True_IsWaterfrontIntracoastal/True_IsWaterfrontLake/True_HasViewOcean/True_HasViewGarden/True_HasViewGolfCourse/True_HasViewRiver/True_HasViewCanal/True_HasViewPond/True_HasViewLake/True_HasViewPool/True_HasPhotos/True_IsOpenHouse/True_IsFenced/True_IsNavigable/True_IsAttached/True_IsDetached/True_IsSemiDetached/True_IsOneStory/True_IsTwoStory/True_IsNonMls/True_IsBoatHouse/True_IsBoatSlip/True_IsDockMooring/

Above is giving an error HTTP Error 404.20 - Not Found

Most likely causes:
    A default document is not configured for the site.
    The URL contains a typographical error.
    Directory browsing is not enabled.

Things you can try:

    Configure a default document for this site. This is commonly default.aspx for ASP.NET and index.php for PHP.
    Review the browser URL.
    Enable directory browsing to allow listing the contents of the directory.

while below URLs are working fine.

http://localhost:10537/Search?Query=True_IsFixerUpper/True_IsNewConstruction/True_HasHorses/True_HasVirtualTour/True_HasGarage/True_IsShortSale/True_IsWaterFront/True_HasSwimmingPool/True_HasGolfCourse/True_IsWithinGatedCommunity/True_IsMobileManufacturedHome/True_IsForclosure/True_HasFireplace/True_Is55Community/True_IsWaterfrontRiver/True_IsWaterfrontBay/True_IsWaterfrontInteriorCanal/True_IsWaterfrontOcean/True_IsWaterfrontOceanAccess/True_IsWaterfrontIntracoastal/True_IsWaterfrontLake/True_HasViewOcean/True_HasViewGarden/True_HasViewGolfCourse/True_HasViewRiver/True_HasViewCanal/True_HasViewPond/True_HasViewLake/True_HasViewPool/True_HasPhotos/True_IsOpenHouse/True_IsFenced/True_IsNavigable/True_IsAttached/True_IsDetached/True_IsSemiDetached/True_IsOneStory/True_IsTwoStory/True_IsNonMls/True_IsBoatHouse/True_IsBoatSlip/True_IsDockMooring/

http://localhost:10537/Search/True_IsFixerUpper/True_IsNewConstruction/True_HasHorses/True_HasVirtualTour/True_HasGarage

Controller:

public class SearchController : BaseController
{
        public ActionResult Index(string Query)
        {
        }
}

Route

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Ignore("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
        "Search", // Route name
        "Search/{*Query}", // URL with parameters
        new { controller = "Search", action = "Index", Query = UrlParameter.Optional } // Parameter defaults
    );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );
}

What could be problem.

解决方案

You got this error because there are too many URL segments in the request.

Check this: http://www.iis.net/learn/extensions/introduction-to-iis-express/iis-80-express-readme
IIS 8.0 Express returns an HTTP 404.20 error for Too Many URL Segments.


UPDATE:

Follow the site below to change the limit of URL segments count.(The default value is 32.)

http://blogs.msdn.com/b/vijaysk/archive/2012/10/11/iis-8-what-s-new-website-settings.aspx

After changing the configuration, the url will pass the validation of segments count.

Now error will throw about exceeding the maxUrlLength.

You need to add following content to the <system.web /> section of your Web.config file.

<httpRuntime maxUrlLength="9999" maxQueryStringLength="9999" />

Then your long request url with many segments works finally!!!

这篇关于控制器动作不会调用如果URL参数为长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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