Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

PartialRouter for Simple Address

$
0
0

Hi!

I'm quite new to EPi - working about half a year, and most of issues I had, was successfully solved with help of this forum and some EPi related blogs (jondjones; mathiaskunto). This time I'm having issue I can't deal with and hoping for advice from more experienced developers.

CMSversion: 10.10.4

The Issue

I have implemented partial router for specific page which just fetches two segments with strings and stores these into RouteData and also simple InitializationModule to register this router.

Everythings is working fine if I'm using full url to navigate to page - I can retrieve data in particular page controller from RouteData ( RouteData.Values[]).

Issue begins when I'm using Simple Address for that page - pages without these additional segments are working fine (routed & rendered), but page with these parameters are returning 404 error.

OK: http://localhost/en/all-posts/post-details/year/number (particular post - full hierarchy)
OK: http://localhost/all-posts/post-details/year/number (particular post - full hierarchy)
OK: http://localhost/en/all-posts (all post - full hierarchy)
OK: http://localhost/posts (all post - full hierarchy)

404: http://localhost/post/year/number (particular post - simple address)
Fail: http://localhost/post (particular post - simple address. Reaches controller but no RouteData)

Am I missing something? How can I make partial router work with SimpleAddress?

Hope that you understand my struggle :D

Used code parts

public class PostViewPagePartialRouter : IPartialRouter
{
	public PartialRouteData GetPartialVirtualPath(PostViewPage content, string language, RouteValueDictionary routeValues, RequestContext requestContext)
	{
		return null;
	}
	public object RoutePartial(PostViewPage content, SegmentContext segmentContext)
	{
		var nextValue = segmentContext.GetNextValue(segmentContext.RemainingPath);
		try
		{
			segmentContext.RouteData.Values["year"] = nextValue.Next;
			segmentContext.RouteData.Values["number"] = nextValue.Remaining;
			segmentContext.RemainingPath = string.Empty;
		}
		catch { }
		return content;
	}
}
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class PartialRoutersInitialization : IInitializableModule
{
	public void Initialize(InitializationEngine context)
	{
		RouteTable.Routes.RegisterPartialRouter(new PostViewPagePartialRouter());
	}
	public void Uninitialize(InitializationEngine context)
	{
		//Add uninitialization logic
	}
}

Viewing all articles
Browse latest Browse all 9076

Trending Articles