ASP.NET MVC Routing in Azure

I have an Azure Web Role project, which was recently MVC'd by another developer. According to the developer, the application works without problems when it runs on it (i.e., as a simple web application). However, when I try to run it in the context of the Azure cloud service, I see several 404 errors. I suspect that something is wrong with the routing. Here's a shortened version of the current RegisterRoutes method, which is part of Global.asax.cs:

public static void RegisterRoutes(RouteCollection routes){ routes.IgnoreRoute("{Services}/{*pathInfo}"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Configuration", "Configuration", new { controller = "Configuration", action = "Index" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Account", action = "Index", id = "" } );} 

When the application starts, the correct view from the action of the index of the account controller will be displayed. However, if I try to proceed to Configuration, I get 404. Convertible if I change the method to this:

 public static void RegisterRoutes(RouteCollection routes){ routes.IgnoreRoute("{Services}/{*pathInfo}"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Account", "Account", new { controller = "Account", action = "Index" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Configuration", action = "Index", id = "" } );} 

I get the correct view from the action of the index of the configuration controller, but I can not go to the view of the account.

I suppose this is a simple problem to solve, but not knowing what was done for MVC, the Azure application and the new one for MVC, I hit my head against the wall.

Here is the machine configuration where I am facing this problem: Windows 7 Ultimate with IIS 7.0 Visual Studio 2008 SP1 ASP.NET MVC 1.0 Windows Azure SDK 1.0

Thoughts?

+2
source share
3 answers

Try using my routing debugger. This can help you understand what is happening. http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

It is strange that the behavior will differ locally than in Azure. In addition, you must publish your controller code (delete the contents of the action methods, we just need to see the method signatures).

If I had to guess, I would suggest that your configuration route (in the first example you gave) should add id = "" to the default section.

+3
source

Haacked: Thanks for pointing me to the debugger. This helped me track down the problem in minutes.

The answer was much simpler than I thought. All this is related to the following line of code:

 routes.IgnoreRoute("{Services}/{*pathInfo}"); 

I included this line to help solve the problem that I encountered with ASP.NET MVC and WCF RIA Services (more on this here ). There should be no parentheses. I do not want to replace the Services. The code should look like this:

 routes.IgnoreRoute("Services/{*pathInfo}"); 

You can read the full entry here .

+1
source

I do not think this is your problem, but you can make sure that the System.Web.Mvc link has its copy Local = true.

-1
source

Source: https://habr.com/ru/post/985311/


All Articles