locked
How to make MVC Site the default page for IIS server? RRS feed

  • Question

  • User-596903714 posted

    I am setting up a test server that will be used to test multiple MVC apps as they are built and published.  To keep things clean, I published my first site to a sub folder of the Default Site but would like it to be the default MVC app for the server.  I thought I could set the index page of the MVC app as the default page in the IIS server configuration but, it just loads the IIS welcome page, not my app.  The server is named  http://testweb and the MVC app is located at http://testweb/app1/ so I set the default page to /app1/Home/Index.cshtml in the default document section and made it the top entry.

    Is there a better way to do this?

    Wednesday, August 30, 2017 3:16 PM

All replies

  • User475983607 posted

    This is an IIS and network (DNS) support support question. 

    IIS has a concept of bindings where the site is bound to a domain and port.  It is best to create a sub domain like test.mydomain.com on the test server and assign port 80 (HTTP) or 443 (HTTPS) so you access the site like any other site.  Then the default URL is just http://test.mydomain.com.  

    Without the domain, simply access the site by http://testweb/appname

    See IIS support for more information.

    https://support.microsoft.com/en-us/help/323972/how-to-set-up-your-first-iis-web-site

    https://technet.microsoft.com/en-us/library/cc772350(v=ws.10).aspx

    https://docs.microsoft.com/en-us/iis/application-frameworks/scenario-build-an-aspnet-website-on-iis/configure-an-asp-net-website-on-iis

    Wednesday, August 30, 2017 6:03 PM
  • User-596903714 posted

    Hi Again,

    We did setup a subdomain and that's what created the problem; a little further explanation may be in order.  The site is not actually called app1 as I originally explained, it's something a little longer and more descriptive e.g. order-system.

    We setup a subdomain called ordersystem with goDaddy and have it setup on a custom port.  So at the moment the URL to access it looks something like this:

    ordersystem.compnayname.com:160000/Order-System/

    the repetition of the words "order system" are silly so I am trying to eliminate the last part of the URL.

    In IIS, there aren't any binding settings for "sub" sites, just the main site so, are you suggesting I create multiple sites instead of using the single default site?

    Wednesday, August 30, 2017 7:47 PM
  • User475983607 posted

    PhillD

    In IIS, there aren't any binding settings for "sub" sites, just the main site so, are you suggesting I create multiple sites instead of using the single default site?

    Yes...

    I don't know what version of IIS you are using but you simply create an application then bind the site.  If you have domain names then you can use port 80 by setting host headers (IIS 6) or just setting the binding in later versions of IIS.

    https://blogs.technet.microsoft.com/chrad/2010/01/24/understanding-iis-bindings-websites-virtual-directories-and-lastly-application-pools/

    https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/bindings/binding

    https://www.digicert.com/ssl-support/ssl-host-headers-iis-7.htm

    The starting page in an application is usually the root default.xxx, index.xxx... but you can set that in the application configuration.  Not the default but the new application you created.

    Wednesday, August 30, 2017 8:43 PM
  • User-596903714 posted

    I'm using IIS 8.5  Unfortunately, the sys admin can't use port 80 externally because it is in use by other services on all available IP's.

    Setting up a new site for each MVC app makes sense instead of creating applications under the default site.

    Thanks again.

    Wednesday, August 30, 2017 9:18 PM
  • User1771544211 posted

    Hi PhillD,

    It seems that you can't set the MVC page as IIS default document, the path you configure as default document should be the physical file path related to the website's root folder.

    When the request comes, the IIS will check if there are files exists at the locations that you configure as IIS default document. However, in MVC you can't request the /Views/ControllerName/ActionName.cshtml directly. In asp.net, we request the domain/ControllerName/Action and then the MVC routing will handle the request.

    So the IIS Default document isn't suitable in your condition, to achieve your requirement, I think you can use the IIS URL Rewrite to rewrite http://testweb to http://testweb/app1/Home/Index.

    To use the URL Rewrite, please first install the IIS URL Rewrite Extension

    Then you can add the following code into your website's web.config file.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        ....
        <system.webServer>
    
            <rewrite>
                <rules>
                    <rule name="URL Rewrite">
                        <match url="^$" />
                        <action type="Rewrite" url="/app1/Home/Index" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

    The following link shows more about how to use IIS URL Rewrite, please take it as reference.

    http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

    Best Regards,

    Jean

    Thursday, August 31, 2017 2:23 AM