如果URL参数很长,则不会调用Controller操作

时间:2014-07-21 09:15:18

标签: asp.net asp.net-mvc iis

仅供参考:我的问题不是404.20 for long url in MVC 3的重复,所以请不要混淆。

我有一个Asp.net MVC应用程序,我有一个接受字符串类型参数的action方法。相同的网址可能很长,如下所示。

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 - 未找到

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.

虽然以下网址工作正常。

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

控制器

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

路线

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

可能有什么问题。

1 个答案:

答案 0 :(得分:1)

您收到此错误,因为请求中的网址段太多。

检查一下: 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.


<强> 更新:

按照以下网站更改网址细分计数的限制。(默认值为32。)

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

更改配置后,网址将通过细分计数验证。

现在错误将超过maxUrlLength。

您需要将以下内容添加到 Web.config 文件的<system.web />部分。

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

然后,您的长段请求网址会有很多段,最终会工作!!!