Search code examples
c#asp.netasp.net-mvc-4iisstart-page

setting homepage in IIS for mvc4 website /application (no forms no.aspx)


as it happens i had a long day solving settings problems and now that i am set with mvc4 (moved from WebForms) and vs2010 .

after deploying to IIS(7 v7.5) i could not make the project load unless i specify the full path to the view . besides putting a static html or aspx page

how is it possible to make it redirect to [MyFirstControl]/[MyFirstView]

is it missing a master ? is it the issue between selecting a Website vs WebApplication ?

i have connected my Ip to a domain name, opened ports in FW for iis , and all i want is to be able to enter the site / application through its domain name rather having to dial in the control + view . so what do i need to do?

by the way i am using basic template as i want minimal volume of code and is it a website by definition or web-application does it actually matter as programmer in .NET no website is a website but an application as you never just put html but a business layer and db.. but i don't understand the differences on the names /terms

Edit

i have googled for long time trying to get it right

 <modules>
      <remove name="UrlRoutingModule-4.0" />
      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>


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

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

Solution

  • You have only registered a single route (the default that is created in a new MVC project):

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

    The defaults argument provides default values when there is no action or no controller in the URL. So when you navigate to the root (/) then the Index action is executed on the HomeController.

    Apparently, you want the root (/) to point to the MyFirstView action on the MyFirstControl controller so in principle you simply have to change the value of the defaults argument. However, your controller class ends with Control but MVC expects it to end with Controller so you have to rename your controller class to MyFirstController and then configure this default route:

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

    Also, using View in an action name is somewhat confusing.

    Routing in ASP.NET is a very important concept and you can learn more about it by reading the article ASP.NET Routing.