1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Database Generated Pages using URL Routing

Database Generated Pages using URL Routing

11 posts, 1 answered
  1. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    13 Nov 2009
    Link to this post

    We wrote a HTTPModule to do Routing, and have the code complete to the level where we know what Sitefinity page URL we want to send the user.  How do we do this?  I figured I could create a CMSManager and GetPage on the URL but the HTTPModule does not accept the returned IPage object as an IHttpHandler.

     

    How do we push to a virtual Sitefinity page from a custom IRouteHandler?  I know it has to be simple....

  2. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    13 Nov 2009
    Link to this post
    OK, here is what we are doing.

    We have about 12 Sitefinity pages setup that need to be mapped to a complex URL structure.  To do this we are trying to use routing, read the URL, look up the categories in our database to determine what type of data we are getting and which of the specific 12 created sitefinity virtual pages should be loaded.  We then load the variables into the routing data, and we want to have sitefinity load the specific page.

    So our original request is something like:  www.mydomain.com/Cat1/Cat2_orProd2/User1_orCat2/actionpage.aspx
    after running some data lookups we determine this request should turn into:

    var1 = cat1
    var2 = User1_orCat2
    var3 = [blank]
    var4 = Cat2_orProd2
    and the sitefinity page that should load is ~/reports/detailedsummaryforuser.aspx

    We are to the point where we know the vars (have them set in the context route data, and we know the sitefinity page that we want loaded, but in our httpmodule we don't know how to pass back the sitefinity page object.
  3. Keith Lusk
    Keith Lusk avatar
    3 posts
    Registered:
    21 Sep 2009
    13 Nov 2009
    Link to this post
    I'm stuck at the same spot. I successfully created an System.Web.Routing.IRouteHandler Class, retrieved and worked with all of my requestContext.RouteData.Values, but am stuck on the IHttpHandler return on the public IHttpHandler GetHttpHandler method.

    Normally with routing I would return the following :
     
    return BuildManager.CreateInstanceFromVirtualPath( stringURL, typeof(Page)) as Page;  
     
     
    Not certain how -or- what to return for the virtual Sitefinity page to be rendered.

     

     

    Here is the setup
    1. Add the following code to Global.Asax

    void Application_Start(object sender, EventArgs e)   
    {  
        // Code that runs on application startup   
        RegisterRoutes(RouteTable.Routes);    
    }  

    --Also in Global.Asax add a route.Add for each pattern you need to trap 

    public static void RegisterRoutes(RouteCollection routes)   
    {  
        routes.Add(  
            "MyRouteName", new Route   
        ("Path/{Category1}/{Category2}/{Action}.Aspx", new MyRouteHandlerClass() //In App Code   
     ));  

    2. Add a Class to App Code:

    public class MyRouteHandlerClass: System.Web.Routing.IRouteHandler   
    {  
        //Constructor  
        public MyRouteHandlerClass(){}  
     
    //Add the Handler  
    public IHttpHandler GetHttpHandler(RequestContext requestContext)   
    {  
        string myAction = requestContext.RouteData.Values["Action"];  
        string myCategory1 =     requestContext.RouteData.Values["Category1"];  
        string myCategory2 =     requestContext.RouteData.Values["Category2"];  
        ...Your Code  
        ..If you need to clear the requestContext.routeData values and assign your own  
        //requestContext.RouteData.Values.Clear();   
        //requestContext.RouteData.Values.Add("Key", stringValue);   
     
    =====HERES THE PROBLEM=====   
    if(MyAction.ToLower() == "action1")   
    {  
    return BuildManager.CreateInstanceFromVirtualPath( "relativePath", typeof(Page)) as Page; //Needs to be an actual page  
    }   
    else if (MyAction.ToLower() == "action2")   
    {   
    return BuildManager.CreateInstanceFromVirtualPath( "relativePath", typeof(Page)) as Page;  
    }  




    To Use the routing data in a control or page it is available from the current request context 

    Must also add the following to Web.Config 

    In Assemblies:
    <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  

    In HttpModules:
    <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
     

  4. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    16 Nov 2009
    Link to this post
    The basic issue is I can't use the provided URL masking and routing function of Sitefinity.  I needed to write my own with more complex code to determine the page variables, and ending URL. 

    I was thinking, another option would be to abandon Routing and use an HTTPModule and URLRewrite the url passing the paramaters via querystring.  If I do that will sitefinity pick up after the rewrite and process the newly defined page?  I was hoping to use routing if possible, but if that is better I can go that way.

    Anyone have any direction on this issue?
  5. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    17 Nov 2009
    Link to this post
    Hey Telerik Team, can you tell me if we are in the right direction here at all? 
     
    Can we use custom routing and push back to Sitefinity, orshould we be using an httpmodule?  Or even can you think of a way for us to make Telerik.Cms.Engine.ContentUrlRewriterService work in thisscenario?
     
    Any feedback would be greatly appreciated as I am holdingthe team on this project till I know what direction to send themin.
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    23 Nov 2009
    Link to this post
    Hi,

    Apologies once again for the delay on this one.

    If we should be honest, there is no easy way to achieve this with Sitefinity.

    We haven't tested completely something like this, but we believe the way to go is the UrlRewriting feature. This is not the Telerik.Cms.Engine.ContentUrlRewriterService. Please check the User Manual -> Application Web.Config file - > URL Rewriter.

    The rewriting will be based on rules. I think that this will suit your needs.

    The routing will be supported in Sitefinity 4.0 though.

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    23 Nov 2009
    Link to this post
    HiGeorgi,
     
    Thanks for lookinginto this for me.  I hate to say it but I am glad that is the answer.  I wasfeeling rather stupid not being able to figure it out and thought it would haveto be an easy answer.  I will visit it again when version 4.0 is available.Till then a URLRewriting we will go.
  8. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    23 Nov 2009
    Link to this post
    Hi Jason Green,

    Thank you very much for the understanding. We will try to be faster next time.
    Good luck with the project.

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    25 Nov 2009
    Link to this post
    I just realized the manual you pointed me at only talks about  using CmsHttpModuleUrlRewrite but we need to write our own httpModule to do this.  The issue we have rules around our urls that make it so we can't use simple rules.  We need to interrogate the URL, look up values in a cached dataset, and determine the final URL from the results.

    We started doing this with routing, and now switched to URL Rewrite.  I thought I could just rewrite to the URL sitefinity is expecting, but the rewrite wants a real page.  So what do I do?  

    How do we make a custom httphandler or httpmodule that will allow us to URLRewrite a URL to a virtual sitefinity page?
  10. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    27 Nov 2009
    Link to this post
    Hello Jason Green,

    Did you resolve the issue?

    We saw that you have posted this in a thread by you:
    ok, I think we figured out a way to simplify our structure enough to use regex and the rules from sitefinity to use the built inurl rewriting functions.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  11. Jason Green
    Jason Green avatar
    53 posts
    Registered:
    18 Sep 2009
    08 Dec 2009
    Link to this post
    Yes, we simplified our URL structure and using regular expressions were able to utilized the advanced URLRewiting features built into Sitefinity.
Register for webinar
11 posts, 1 answered