locked
ISP IIS default documents not working for MVC route RRS feed

  • Question

  • User1868852945 posted

    How can I have my MVC starting page Index/IndexView be recognized by IIS as a valid starting document so when user types in domain name alone, it routes to Index/IndexView?  I have tried every combination possible such as Index/IndexView/indexView.cshtml, etc., but the only way to get the app to come up is to type out the full route - http://www.schematrack.com/Index/IndexView.

    I tried a redirect with an index.html redirecting to http://www.schematrack.com/Index/IndexView, but this gets 404 resource not found error.

    The redirect code is...

    var host = window.location.host;
    var protocol = window.location.protocol;
    var url = protocol + "//" + host + "/Index/IndexView";
    window.location.replace(url);

    The ISP ASP.NET version is set to 4.x.  

    Thanks if you can advise how to get a route recognized by IIS default documents.

    Saturday, December 29, 2018 10:54 PM

Answers

  • User753101303 posted

    Hi,

    Usually you just register your route with default values :

    routes.MapRoute("default","{controller}/{action}/{id}", new {controller="Home"",action="Index"]);

    And then entering https://site.com/ will serve https://site.com/Home/Index.

    Edit: if you really want to keep your current approach use maybe alert(url); and triple check it is the correct value that you are testing. Ah try :

    protocol + "://" + host + "/Index/IndexView"; // Added : after the protocol

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 31, 2018 10:44 AM
  • User-474980206 posted

    IIS default documents are not support by MVC controllers. as suggested you just make a default route. if you used the default route,

     /Index/IndexView

    is looking for an action named IndexView on the Index controller. to make the default, just change the default route to:

    routes.MapRoute("default","{controller}/{action}/{id}", new {controller="Index",action="IndexView"]);

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 31, 2018 5:24 PM
  • User1520731567 posted

    Hi gunderj,

    MVC does not support IIS default documents.

    MVC has its own set of routing rules.

    If you would like to change the url by IIS,you could use url rewrite.

    But I suggest you could set the route by MVC default routing configuration.

    click App_Start->RouteConfig.cs, and modify the code,like:

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

    If you want routes to Index/IndexView,when user types in domain name alone.

    You could modify the defaults,like:

               defaults: new { controller = "Index", action = "IndexView", id = UrlParameter.Optional }

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 1, 2019 2:03 AM
  • User1868852945 posted

    I marked all the above as answers though I did not prove each one.

    I ended up adding routes.IgnoreRoute("");  to the route as below and this works fine.

    Thanks.

     

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

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

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 2, 2019 5:06 AM

All replies

  • User753101303 posted

    Hi,

    Usually you just register your route with default values :

    routes.MapRoute("default","{controller}/{action}/{id}", new {controller="Home"",action="Index"]);

    And then entering https://site.com/ will serve https://site.com/Home/Index.

    Edit: if you really want to keep your current approach use maybe alert(url); and triple check it is the correct value that you are testing. Ah try :

    protocol + "://" + host + "/Index/IndexView"; // Added : after the protocol

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 31, 2018 10:44 AM
  • User-474980206 posted

    IIS default documents are not support by MVC controllers. as suggested you just make a default route. if you used the default route,

     /Index/IndexView

    is looking for an action named IndexView on the Index controller. to make the default, just change the default route to:

    routes.MapRoute("default","{controller}/{action}/{id}", new {controller="Index",action="IndexView"]);

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 31, 2018 5:24 PM
  • User1520731567 posted

    Hi gunderj,

    MVC does not support IIS default documents.

    MVC has its own set of routing rules.

    If you would like to change the url by IIS,you could use url rewrite.

    But I suggest you could set the route by MVC default routing configuration.

    click App_Start->RouteConfig.cs, and modify the code,like:

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

    If you want routes to Index/IndexView,when user types in domain name alone.

    You could modify the defaults,like:

               defaults: new { controller = "Index", action = "IndexView", id = UrlParameter.Optional }

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 1, 2019 2:03 AM
  • User1868852945 posted

    I marked all the above as answers though I did not prove each one.

    I ended up adding routes.IgnoreRoute("");  to the route as below and this works fine.

    Thanks.

     

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

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

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 2, 2019 5:06 AM