简体   繁体   中英

Asp.net MVC Routing Issue 403.14

one of my controller could not load "Index".for example :

 http://localhost:51638/Reserve/

doesn't work.but http://localhost:51638/Reserve/Index works. and this problem is just for one of my controller and other is correct. and my RouteConfig is:

public static void RegisterRoutes(RouteCollection routes)
        {


            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // BotDetect requests must not be routed
            routes.IgnoreRoute("{*botdetect}",
              new { botdetect = @"(.*)BotDetectCaptcha\.ashx" });
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "UserHome", action = "Index", id = UrlParameter.Optional }
            );
        }

after delete the controller and add Controller again it wasn't fix. and encounter to this error page:

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

and this is my Controller Code

public class ReserveController : Controller
{
    //
    // GET: /Reserve/
    public ActionResult Index()
    {
        return View();
    }
}

If you have controller named Reserve Controller, and a directory named Reserve , the routing will go to the directory unless you supply the full route. This is why you get the 403.14 error.

So, change the name of the controller or the directory.

You can add another routhe with default route for "Reserve"

routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Reserve", action = "Index", id = UrlParameter.Optional }
            );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM