Reputation: 7562
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.
Upvotes: 0
Views: 1934
Reputation: 2995
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!!!
Upvotes: 1