I'm trying to deploy a MVC application onto a server for demonstration purposes. I can access the MVC application without a problem using localhost. I get a 404 error when accessing any URL other then the default URL after publishing MVC app to new server.
The new server has the latest version of MVC and .Net 3.5 installed. I can access the default URL which tells me that MVC is working, but any other link fails. Why would the app work using localhost:[port number] and not the url for the dev server? How
can you trouble shoot this? I even migrated the "default" MVC application that's created for new MVC projects to the server and I get the same issue when clicking on the About url. Any ideas?
1 // Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable 2 // automatic support on IIS6 and IIS7 classic mode
So, what are the rules around where .mvc can be added in new Route? The instructions just say to place it after {controller}, however, I have several routes that
do not signify a {controler} in the route pattern. How do you handle .mvc in this situation? need some advice. Thanks for your help.
IIS7 has a mode called "integrated mode". Integrated mode can call an ASP.NET Http Module without invoking the ASP.NET asapi dll. This allows IIS7 to route the extension-less urls. In IIS6 and II7 running classic pipeline mode IIS cannot check the rout without
invoking the ASP.NET isapi dll. The problem is that IIS does not know to invoke the ASP.NET isapi dll unless it sees an extension associated with ASP.NET. The default MVC routes are extension-less therefore IIS does not know what to do with them.
This explains the problem.
The solution is to add an ASP.NET extension to your urls (.mvc, .aspx, etc...). It doesn't matter where in your route you add the extension (after your controller, at the end, where ever you want) as long as you add it.
Another option is to use wildcard associations and to have all requests coming to your server be routed to the ASP.NET isapi dl. this has some performance issues but it will allow you to keep your pretty extension-less urls even in IIS6
routes.MapRoute("Basic",
"{controller}.mvc/{action}/{id}",
new { controller = "Home", action = "Index", id = "" },
new { controller = @"[^\.]*" }
);
routes.MapRoute("Default",
"Default.aspx",
new { controller = "Home", action = "Index", id = "" }
);
In IIS 5 i have a virtual directory pointing to my web app with the name GTS
Whenever i try to browse from localhost i get
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.
is the built in VS webserver all request are sent to ASP.NET so even if the url is extension-less it gets executed. In IIS urls are only sent to ASP.NET if they have a file extension associated with ASP.NET.
To run your app you must have an extension associated with ASP.NET in your routes.
Try changing the .mvc to .aspx and see if this fixes it
I am using IIS7 and the following routeer code in global.asax.cs file:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Basic", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" }, // Parameter defaults
new { controller = @"[^\.]*" } // Parameter constraints
);
routes.MapRoute("Default",
"Default.aspx",
new { controller = "Home", action = "Index", id = "" }
);
}
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
It is working fine for me. Do you have added Default.aspx and Default.aspx.cs page as below:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="namespaceName._Default" %>
<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%>
public partial class _Default : Page
{ public void Page_Load(object sender, System.EventArgs e)
{
Response.Redirect("~/Home");
}
}
tschreck
Member
3 Points
18 Posts
deploying MVC application
Apr 27, 2008 11:43 PM|LINK
I'm trying to deploy a MVC application onto a server for demonstration purposes. I can access the MVC application without a problem using localhost. I get a 404 error when accessing any URL other then the default URL after publishing MVC app to new server. The new server has the latest version of MVC and .Net 3.5 installed. I can access the default URL which tells me that MVC is working, but any other link fails. Why would the app work using localhost:[port number] and not the url for the dev server? How can you trouble shoot this? I even migrated the "default" MVC application that's created for new MVC projects to the server and I get the same issue when clicking on the About url. Any ideas?
MVC deployment
mateo666
Member
4 Points
26 Posts
Re: deploying MVC application
Apr 28, 2008 05:18 AM|LINK
Hey i was just having the same problem and found this thread.
Default render a blank page but every other links dont work.
My default route is not redirecting neither to what it is supposed Home/Index. This behavior is also the same when i debug in vs?
Anyone??
tschreck
Member
3 Points
18 Posts
Re: deploying MVC application
Apr 28, 2008 06:31 AM|LINK
I found in Global.asax that you are supposed to add .mvc to the route like this (line 1):
1 routes.Add("SearchResults", new Route(".mvc/searchresults/{ticks}/{mealtypeid}/{viewsource}/{foodgroupid}/{foodname}", new MvcRouteHandler())
2 {
3 Defaults = new RouteValueDictionary(new
4 {
5 controller = "Search",
6 action = "SearchResults",
7 foodgroupid = 0,
8 foodname = ""
9 }),
10 });
The default instructions in Global.asax says to:
1 // Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable2 // automatic support on IIS6 and IIS7 classic mode So, what are the rules around where .mvc can be added in new Route? The instructions just say to place it after {controller}, however, I have several routes that do not signify a {controler} in the route pattern. How do you handle .mvc in this situation? need some advice. Thanks for your help.
srulyt
Participant
1073 Points
230 Posts
Re: deploying MVC application
Apr 28, 2008 06:13 PM|LINK
IIS7 has a mode called "integrated mode". Integrated mode can call an ASP.NET Http Module without invoking the ASP.NET asapi dll. This allows IIS7 to route the extension-less urls. In IIS6 and II7 running classic pipeline mode IIS cannot check the rout without invoking the ASP.NET isapi dll. The problem is that IIS does not know to invoke the ASP.NET isapi dll unless it sees an extension associated with ASP.NET. The default MVC routes are extension-less therefore IIS does not know what to do with them.
This explains the problem.
The solution is to add an ASP.NET extension to your urls (.mvc, .aspx, etc...). It doesn't matter where in your route you add the extension (after your controller, at the end, where ever you want) as long as you add it.
Another option is to use wildcard associations and to have all requests coming to your server be routed to the ASP.NET isapi dl. this has some performance issues but it will allow you to keep your pretty extension-less urls even in IIS6
Good Luck
mateo666
Member
4 Points
26 Posts
Re: deploying MVC application
Apr 28, 2008 07:12 PM|LINK
Not sure i'm following you here.
My routes are defined like this
routes.MapRoute("Basic",
"{controller}.mvc/{action}/{id}",
new { controller = "Home", action = "Index", id = "" },
new { controller = @"[^\.]*" }
);
routes.MapRoute("Default",
"Default.aspx",
new { controller = "Home", action = "Index", id = "" }
);
In IIS 5 i have a virtual directory pointing to my web app with the name GTS
Whenever i try to browse from localhost i get
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: /gts/Home.mvc
If i try from vs everything is fine?
srulyt
Participant
1073 Points
230 Posts
Re: deploying MVC application
Apr 29, 2008 02:22 PM|LINK
is the built in VS webserver all request are sent to ASP.NET so even if the url is extension-less it gets executed. In IIS urls are only sent to ASP.NET if they have a file extension associated with ASP.NET.
To run your app you must have an extension associated with ASP.NET in your routes.
Try changing the .mvc to .aspx and see if this fixes it
gyan_flip
Member
129 Points
77 Posts
Re: deploying MVC application
May 02, 2008 10:46 AM|LINK
I am using IIS7 and the following routeer code in global.asax.cs file:
public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "Basic", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" }, // Parameter defaults new { controller = @"[^\.]*" } // Parameter constraints ); routes.MapRoute("Default", "Default.aspx", new { controller = "Home", action = "Index", id = "" } ); } protected void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); }It is working fine for me. Do you have added Default.aspx and Default.aspx.cs page as below:public partial class _Default : Page
{
public void Page_Load(object sender, System.EventArgs e)
{
Response.Redirect("~/Home");
}
}
gayupk
Member
26 Points
60 Posts
Re: deploying MVC application
May 12, 2008 07:19 AM|LINK
I am using IIS 5 . The error is 404. I added .mvc in controller but still it isn't working. Do i need to have a wildcard? If so how?
Kindly help.
huamiao
Member
8 Points
4 Posts
Re: deploying MVC application
May 12, 2008 07:39 AM|LINK
Did you try to add an application mapping for extension .mvc to aspnet_isapi.dll in iis manager?
gayupk
Member
26 Points
60 Posts
Re: deploying MVC application
May 12, 2008 09:00 AM|LINK
It is not allowing me to add the extension.
.mvc extension i mean. The ok button is not enabled for me to add the extension.