仅供参考:我的问题不是重复的MVC 3 中的长 url 为 404.20 https://stackoverflow.com/questions/20798392/404-20-for-long-url-in-mvc-3所以请不要混淆。
我有一个 Asp.net MVC 应用程序,其中有一个接受字符串类型参数的操作方法。其 URL 可能会很长,如下所示。
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.
而下面的 URL 工作正常。
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)
{
}
}
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
);
}
可能是什么问题。