Reputation: 1989
I've setup a site on our webserver using IIS8. The URL is something link ABC.mycompany.com. When I go to ABC.mycompany.com, I get a not found error:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
If I go to ABC.mycompany.com/Home/InstrumentList, it shows the the correct page I want to start on. How do I get it to start at this route?
In Visual Studio 2013, I have Home/InstrumentList set as my start action and that works fine. I've looked at several examples where they reference default and index pages, but my application doesn't have any of these. Also, there are references to .aspx pages, but there are no .aspx pages in my app, just .cshtml Views and .cs Controllers. I also have seen things about adding routes, but I'm unsure where to put them in global.asax.cs (in ApplicationStart? outside it? in a different method? just alone?). I also don't know what to change to work for mine (change index to InstrumentListing or leave it alone). Nothing has worked for me so far.
Here's one of my attempts using global.asax.cs where I tried to add a register route method:
namespace GPC
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
WebApiConfig.Register(GlobalConfiguration.Configuration);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default",
"{controller}/{action}/{Filtre}",
new { controller = "Home", action = "Index", Filtre = UrlParameter.Optional });
}
}
}
Here are some of the sites I've used, but nothing has worked for me:
http://weblog.west-wind.com/posts/2013/Aug/15/IIS-Default-Documents-vs-ASPNET-MVC-Routes
cannot set Default route for MVC project
http://weblogs.asp.net/imranbaloch/editing-routes-in-mvc
I'd appreciate if someone could show me how to get ABC.mycompany.com/Home/InstrumentList to show when the user goes to ABC.mycompany.com.
Upvotes: 4
Views: 12333
Reputation: 12491
I'm not sure, but your RegisterRoutes
method should be in RouteConfig
class that by default should be in App_Start
foulder of MVC project. This is not a method in MvcApplication
class that located in Global.asax.cs
as i see in your question.
Then you should only change RegisterRoutes
method like this to set different default controller action:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default",
"{controller}/{action}/{Filtre}",
new { controller = "Home", action = "InstrumentList", Filtre = UrlParameter.Optional });
}
Upvotes: 4