Can IIS 7 set the default url to an MVC 3 area

1k Views Asked by At

I have an MVC 3 solution that is broken down into areas. I can access the application in the following ways for example: //myapp/ or //myapp/external or //myapp/internal. What I am trying to accomplish in IIS 7 is to set the default URL (in my case would be //myapp) to //myapp/internal.

So anytime someone navigates to //myapp they are redirected to //maypp/internal (internal is the name of the area I have set up in MVC).

I am really looking for a way to do this on the server and not in global.asax. The reason being is because this app will be on multiple servers and I don't want to have to change the default route every time I need to deploy my app.

Thanks for the help.

2

There are 2 best solutions below

0
On BEST ANSWER

I ended up solving my issue the following way:

a. In my Web.Internal.config file I added this transformation:

<appSettings>
    <add key="Environment" value="Production Internal(Live)" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>         

Now when I deploy my solution to my internal site the Environment value in my Web.config is overwritten with "Production Internal(Live)"

b. I then added a check in my default controller and action to lookup the Environment value in the Web.config

var InternalorExternalSite = Convert.ToString(ConfigurationManager.AppSettings["Environment"]);

if (InternalorExternalSite == "Production Internal(Live)")
    {
        return RedirectToAction("", "", new { area = "Internal" });
    }

The above code will check if the Environment value is equal to "Production Internal(Live)" in my case and redirect the request to the Area "Internal".

Now when an internal user navigates to http://www.internalsite.com they are redirected to the Area http://www.internalsite.com/internal

When an external user navigates to http://www.externalsite.com they are not redirected to any area, but if you needed to you could redirect the user to any area based on the above.

5
On

The easiest way is to create a default controller at //myapp/ that 301's the user to //myapp/internal. There will always be people who type mydomain.com and suddenly get nothing.

Alternatively, create a specific route in the main Global.asax.cs that matches blank, and routes to the specified controller, action, and area. This pretty much sinks the "area is completely separate" concept though.