Search code examples
asp.net-mvcasp.net-mvc-routing

Getting forbidden (403.14) when not going to /index but just /


With ASP.NET MVC, I have code as below and the standard route definition. When I navigate to mysite.com/ExtjsRun I get a 403.14 error but when I go to mysite.com/ExtjsRun/index I get the controller executed.

My question is how to get the route /ExtjsRun to default to my index method.

    using System.Web.Mvc;
    using WebApp.Models;

    namespace WebApp.Controllers
    {
        public class ExtJsRunController : Controller
        {

            [MultiTenantControllerAllow("svcc,angu")]
            public ActionResult Index()
            {
                var str = "/ExtjsRun/" + Tenant.Name;
                return Redirect(str);
            }

        }

    }

Routing:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            namespaces: new[] {"WebApp.Controllers"},
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home",
                action = "Index",
                id = UrlParameter.Optional }
        );

Solution

  • Change the Routing code as below

    public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                namespaces: new[] {"WebApp.Controllers"},
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "ExtJsRun",
                    action = "Index",
                    id = UrlParameter.Optional }
            );
    

    You are not set the default controller to ExtJsRun and action to Index. By your code, the iis server searches for the Home controller and Index Action in that controller, that's the reason for your access denial
    Hope this helps