Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello.
I need to set up custom Ruotes.
I made this, according to this documentation: http://our.umbraco.org/documentation/Reference/Mvc/custom-routes
so, my global assax file is
<%@ Application Codebehind="Global.asax.cs" Inherits="MySite.MvcApplication" Language="C#" %>
and cs file is
public class MvcApplication : Umbraco.Web.UmbracoApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
// Parameter defaults
);
"Pipe", // Route name
new {controller = "Pipe", action = "Index", id = UrlParameter.Optional});
protected override void OnApplicationStarted(object sender, EventArgs e)
base.OnApplicationStarted(sender, e);
RegisterRoutes(RouteTable.Routes);
protected void Application_Start()
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
after that my custom route works but, if I want to view other pages of my site, I see an empty page.
custom route's adding to umbracoReservedUrls or umbracoReservedPaths did not help to resolve the problem
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd, ~/Pipe/Index.aspx" />
<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/Pipe/" />
Please, help
up fot this topic.
I realy need to fix this asap :(
From the looks of it your first route definition is catching everything pretty much {controller}/{action}/{id} - That's why your site doesn't work.
You need to use a more specific route definition 'pipe/{id}' for example
Any luck with this? I'm in a situation where I want an custom MVC controller (and not one that inherits RenderMvcController)
Have a look at the blog post listed at the bottom of the docs here: https://github.com/umbraco/Umbraco4Docs/blob/master/Documentation/Reference/Templating/Mvc/custom-routes.md Shannons blog post goes into a bit more detail about custom routes, maybe something on there will help?
Yes indeed, that does the trick.
Using something like:
public void OnApplicationStarted( UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { //Create a custom route RouteTable.Routes.MapRoute( "test", "Products/{action}/{id}", new { controller = "MyProduct", action = "Product", id = UrlParameter.Optional }); }
And the fun thing is, that your ProductsController is allowed the extend Mvc.Controller and doesn't have to be an UmbracoRenderController
This helped me a lot! Thank you for sharing!
hi @nojaf,
I have tried it on Umbraco 7 and getting some issues, what I have tried so far is:
1) Created MVC project and added a controller into it
2) Added routes as OnApplicationStarted in global.asax.cs.
3) Compiled and copied the DLL to umraco website's bin folder
4) Copied Views to hte Views folder
Now when i try go to my controller i.e. http:\\localhost\Test\Index, it gives me 404.
What have I missed?
Thanks in advance
Satjinder
I think step 2 isn't correct, you should add the route in a custom Umbraco Event class. Create an ApplicationEventHandler and try adding the route there.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
custom routing
Hello.
I need to set up custom Ruotes.
I made this, according to this documentation: http://our.umbraco.org/documentation/Reference/Mvc/custom-routes
so, my global assax file is
<%@ Application Codebehind="Global.asax.cs" Inherits="MySite.MvcApplication" Language="C#" %>
and cs file is
public class MvcApplication : Umbraco.Web.UmbracoApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
// Parameter defaults
);
routes.MapRoute(
"Pipe", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {controller = "Pipe", action = "Index", id = UrlParameter.Optional});
}
protected override void OnApplicationStarted(object sender, EventArgs e)
{
base.OnApplicationStarted(sender, e);
RegisterRoutes(RouteTable.Routes);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
}
}
after that my custom route works but, if I want to view other pages of my site, I see an empty page.
custom route's adding to umbracoReservedUrls or umbracoReservedPaths did not help to resolve the problem
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd, ~/Pipe/Index.aspx" />
<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/Pipe/" />
Please, help
up fot this topic.
I realy need to fix this asap :(
From the looks of it your first route definition is catching everything pretty much {controller}/{action}/{id} - That's why your site doesn't work.
You need to use a more specific route definition 'pipe/{id}' for example
Any luck with this? I'm in a situation where I want an custom MVC controller (and not one that inherits RenderMvcController)
Have a look at the blog post listed at the bottom of the docs here: https://github.com/umbraco/Umbraco4Docs/blob/master/Documentation/Reference/Templating/Mvc/custom-routes.md Shannons blog post goes into a bit more detail about custom routes, maybe something on there will help?
Yes indeed, that does the trick.
Using something like:
This helped me a lot! Thank you for sharing!
hi @nojaf,
I have tried it on Umbraco 7 and getting some issues, what I have tried so far is:
1) Created MVC project and added a controller into it
2) Added routes as OnApplicationStarted in global.asax.cs.
3) Compiled and copied the DLL to umraco website's bin folder
4) Copied Views to hte Views folder
Now when i try go to my controller i.e. http:\\localhost\Test\Index, it gives me 404.
What have I missed?
Thanks in advance
Satjinder
I think step 2 isn't correct, you should add the route in a custom Umbraco Event class. Create an ApplicationEventHandler and try adding the route there.
is working on a reply...