ASP.NET MVC How-to use routes when application is published as SubProject of a domain?
-
03-07-2019 - |
Question
i have a webapp which works perfectly when debugged and tested locally. However when I publish the site to a productionserver the routing is messed up. This is because it runs as a sub-project on the productionserver.
Testing: http://localhost:xxx/ Production: http://remotehost/webapp/
How should I setup routing?
This is my current routing setup (mostly default). The server displays the default Controller action when I visit http://remotehost/webapp/. But when I hard-code the controller (http://remotehost/webapp/Project/ it doesn't work...
Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
routes.MapRoute("ProjectsByCategory", "Project/Category/{id}", _
New With {.controller = "Project", .action = "ListByCategory", .id = ""}, _
New With {.id = "^[0-9]+"})
routes.MapRoute( _
"Default", _
"{controller}/{action}/{id}", _
New With {.controller = "Project", .action = "Index", .id = ""} _
)
End Sub
Solution
To me it sounds like it might be related to publishing on iis 6. There's an article here about that.
For me a similar problem was resolved by adding a 'Wildcard application map':
- In IIS, right click and choose Properties for the virtual directory in question
- choose Virtual directory tab
- choose Configuration
- click Insert
- enter the path to aspnet-isapi.dll (typically c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll).
OTHER TIPS
By the way, the routing seems to be working on application level. No need to bother your domainname or higher directory names.