Mvc3 web app routing directly on index.cshtml

2019-04-13 06:44发布

问题:

I have created and host nvc3 web app now problem is when I open my www.abc.com it is opening index.cshtml i.e home page of mvc web app

but I dont want that to be open when I open www.abc.com I have one static page called index.htm should be open first

in mvc3 Global.asax code:

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

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

How can I render to http://www.abc.com/mypage.html ? what should I please help.

回答1:

ashuthinks,

Based on your revised comments for the question. If you just want to show the 'Under contruction' type page with no links, then you can modify the web.config and add an app_offline.htm file. here's what those changes would look like:

web.config (bare bones):

<?xml version="1.0"?>
<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
</configuration>

app_offline.htm:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Your site title</title>
</head>
<body>
  <div>
    <span>Your Company name</span>
    <h1>Sorry, server maintenance in progress </h1> 
    <h2>Please contact <a href="mailto:mycontact@mycompany.com">John Doe</a> on 000 123 456789 for further information</h2>
  </div>
</body>
</html>

when you need to put the site live, simply rename the above files to web.config_offline and app_offline.htm_offline and bring your 'normal' web.config into play. There are of course many ways to skin this cat but this has worked well with previous projects that I've worked on.

see:

http://weblogs.asp.net/scottgu/archive/2006/04/09/442332.aspx

for further details.