Hi to all,
I'm trying to create and view my Custom Route to view some external data.
I wrote this code following the official umbraco documentation but it don't work.
public class HkRegisterEvents : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
RouteTable.Routes.MapUmbracoRoute(
name: "HKRecycleBin",
url: "HKRecycleBin/{action}",
defaults: new
{
controller = "HKRecycleBin",
action = "Index"
},
new HKRouteHandler(_pageNodeId));
}
}
public class HKRecycleBinController : RenderMvcController
{
public ActionResult Index(RenderModel model)
{
return View("HK/RecycleBin.cshtml", model);
}
}
public class HKRouteHandler : UmbracoVirtualNodeRouteHandler
{
private object _pageNodeId;
public HKRouteHandler(object pageNodeId)
{
_pageNodeId = pageNodeId;
}
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
{
UmbracoHelper helper = new UmbracoHelper(umbracoContext);
string alias = typeof(HKRecycleBinController).Name;
return helper.TypedContentAtRoot()
.First()
.Descendants()
.First(d => d.DocumentTypeAlias.InvariantEquals(alias));
}
}
I think that the problem is that there isn't a real node in Umbraco and when I try to view my custom url "http://localhost:7612/HkRecycleBin/Index", I don't see nothing and in the Trace Log I see an "Umbraco has no content" Warning.
I tried also to inherits my controller from SurfaceController...but nothing.
This is a service page and I wouldn't create a specific node in the content.
OK...at the moment I solved using the umbraco route hijacking method...so I created my custom datatype, template and node used by my custom controller.
It solve the problem at this moment but this is not what I want.
My target is to remove my custom umbraco node in the content and use only my custom view as a external page.
Think the FindContent should actually be able to find content somewhere in the content tree. And your HKRecycleBinController will not give an alias for a document type.
For fake content, not actually having an entry in the tree (what you want right?), just create a route to an action in a surface controller. And let that action output your stuff.
My custom route doesn't display anything
Hi to all, I'm trying to create and view my Custom Route to view some external data. I wrote this code following the official umbraco documentation but it don't work.
I think that the problem is that there isn't a real node in Umbraco and when I try to view my custom url "http://localhost:7612/HkRecycleBin/Index", I don't see nothing and in the Trace Log I see an "Umbraco has no content" Warning.
I tried also to inherits my controller from SurfaceController...but nothing.
This is a service page and I wouldn't create a specific node in the content.
Adriano
OK...at the moment I solved using the umbraco route hijacking method...so I created my custom datatype, template and node used by my custom controller.
It solve the problem at this moment but this is not what I want.
My target is to remove my custom umbraco node in the content and use only my custom view as a external page.
Can anyone help me? Thank you in advance
To start I see you are not really following the documentation. ;)
Documentation says ApplicationStarted, not ApplicationStarting.
And I guess it your case you can drop all pageNodeId references but possibly this is just some sample code.
{action} parameter is for future coding?
(all just to think together with you, I know I am not actually solving the issue)
You're right.
Think the FindContent should actually be able to find content somewhere in the content tree. And your HKRecycleBinController will not give an alias for a document type.
For fake content, not actually having an entry in the tree (what you want right?), just create a route to an action in a surface controller. And let that action output your stuff.
No need for a custom route handler.
Thank you Roy,
I already tried to inherits from SurfaceController instead of RenderMvcController (and removed the HKRouteHandler), but it didn't work.
Surely I did something wrong I'll try again Thanks again for the support
is working on a reply...