Controller action doesn’t call if URL parameter is long

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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!!!


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x