Help! I can't figure out why my area produces a 404 on my live server and works fine locally. I found similar posts that say it has something to do with the namespace, but couldn't figure it out.
Code here for global.asax.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "Login", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
AutoMapperBootstrapper.CreateMappings();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
ControllerBuilder.Current.DefaultNamespaces.Add("NationalMis.WebUI.Controllers");
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
BundleTable.Bundles.RegisterTemplateBundles();
}
Code for AreaRegistration:
namespace NationalMis.WebUI.Areas.AnnualReport
{
public class AnnualReportAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "AnnualReport";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"AnnualReport_default",
"AnnualReport/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new[] { "NationalMis.WebUI.Areas.AnnualReport.Controllers" }
);
}
}
}
This looks right to me, are you sure that you have areas available on the server. Also you might want to look into Application's Error event and see what is going on.
mvc4u
0 Points
15 Posts
Area routes produce 404 on production server, but work locally
Nov 30, 2012 11:23 PM|LINK
Help! I can't figure out why my area produces a 404 on my live server and works fine locally. I found similar posts that say it has something to do with the namespace, but couldn't figure it out.
Code here for global.asax.cs:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Account", action = "Login", id = UrlParameter.Optional } // Parameter defaults ); routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); AutoMapperBootstrapper.CreateMappings(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); ControllerBuilder.Current.DefaultNamespaces.Add("NationalMis.WebUI.Controllers"); ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); BundleTable.Bundles.RegisterTemplateBundles(); }Code for AreaRegistration:
namespace NationalMis.WebUI.Areas.AnnualReport { public class AnnualReportAreaRegistration : AreaRegistration { public override string AreaName { get { return "AnnualReport"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "AnnualReport_default", "AnnualReport/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, new[] { "NationalMis.WebUI.Areas.AnnualReport.Controllers" } ); } } }Help! Going crazy here.
Thanks,
Dan
CPrakash82
All-Star
18720 Points
2899 Posts
Re: Area routes produce 404 on production server, but work locally
Nov 30, 2012 11:27 PM|LINK
How you are generating the Urls? Via ActionLink ? Give us some sample what url you are trying?
mvc4u
0 Points
15 Posts
Re: Area routes produce 404 on production server, but work locally
Nov 30, 2012 11:33 PM|LINK
Thanks for the quick response! So I use this: @Html.ActionLink("Annual Report", "Index", "Section1", new { area = "AnnualReport" }, null)
Or just navigating to /AnnualReport/Section1 works locally, but fails on the live server.
CPrakash82
All-Star
18720 Points
2899 Posts
Re: Area routes produce 404 on production server, but work locally
Nov 30, 2012 11:46 PM|LINK
This looks right to me, are you sure that you have areas available on the server. Also you might want to look into Application's Error event and see what is going on.
mvc4u
0 Points
15 Posts
Re: Area routes produce 404 on production server, but work locally
Nov 30, 2012 11:48 PM|LINK
Anyone? I'm desperate. I'll PayPal someone $5 for a beer if the answer works! So many hours wasted. Please help!
mvc4u
0 Points
15 Posts
Re: Area routes produce 404 on production server, but work locally
Dec 01, 2012 12:03 AM|LINK
Areas are on the server. How do I use Application_Error to log the error, instead of seeing the IIS 404 error?
CPrakash82
All-Star
18720 Points
2899 Posts
Re: Area routes produce 404 on production server, but work locally
Dec 01, 2012 12:08 AM|LINK
Here is one article, which explains about it.
http://www.codeproject.com/Articles/422572/Exception-Handling-in-ASP-NET-MVC
mvc4u
0 Points
15 Posts
Re: Area routes produce 404 on production server, but work locally
Dec 01, 2012 12:23 AM|LINK
Here is someone with the exact same issue, but I don't understand the solution, http://forums.asp.net/t/1643817.aspx#4259825
Please take a quick read!
mvc4u
0 Points
15 Posts
Re: Area routes produce 404 on production server, but work locally
Dec 01, 2012 12:45 AM|LINK
OK, upping it to $10! I'm out of ideas...
CPrakash82
All-Star
18720 Points
2899 Posts
Re: Area routes produce 404 on production server, but work locally
Dec 01, 2012 01:02 AM|LINK
Can you add below code in your Global.asax file and see what is the exception and details with stack trace.
protected void Application_Error(object sender, EventArgs e) { var ex = Server.GetLastError(); // see what is inside the ex - Message & Stacktrace }