How do I construct a dynamic page url in Sitefinity?

Posted by Community Admin on 03-Aug-2018 23:51

How do I construct a dynamic page url in Sitefinity?

All Replies

Posted by Community Admin on 18-Feb-2011 00:00

We have a main landing page:

www.ourwebsite.com/home/

And from there, we have different pages for each customer category, in our case by state.

www.ourwebsite.com/home/wa/
www.ourwebsite.com/home/ca/
www.ourwebsite.com/home/or/
www.ourwebsite.com/home/nv/

Each of those customer category pages are exactly the same, except that they pull data from the database for their category/region based on the url string. Washington customers get a washington version of their page because of the /wa/ in the address. Therefore they can bookmark their territory page.

My question: can this be done in Sitefinity? Is there any way to build a page that uses a url param to load data for a common template? All widgets on the page should load data filtered by that same url param.

I know how to build the widgets that will filter the data based on that url param, but I'm not sure how to get a base page in Sitefinity with different urls like that.

Any hints, help or direction helps!
Thanks,
Dan

Posted by Community Admin on 03-Mar-2011 00:00

Hi Dan,

Sitefinity will load the last valid page in the path of the requested URL and the rest of the URL will be treated as URL parameters. In your example, no matter what you place after ~/home, the home page will be loaded and you can access the rest in the URL as parameters.

To test this, do the following test:

1.       Create a user control, let’s say MyControl.ascx in the root of the site.

2.       Add a Label to the User Control.

3.       Add the following code in the code behind file:

 

public partial class MyControl : System.Web.UI.UserControl
    protected void Page_Load(object sender, EventArgs e)
    
        this.Label1.Text = String.Empty;
        var parms = (string[])this.Request.RequestContext.RouteData.Values["Params"];
        if (parms != null)
        
            foreach (var param in parms)
                this.Label1.Text += param + "</br>";
        
    

 

 

4.       Add the user control to the Page Toolbox. See this instructions how to add user control to the toolbox: http://www.sitefinity.com/documentation/how-to-create-a-widget/creating-a-widget-as-a-user-control/register-the-widget-in-sitefinity.aspx

5.       Drop that control to your home page

NOTE: this behavior is subject to change in the near future because a lot of people perceive it as bug, since we don’t throw HTTP 404 exception. Nevertheless the current behavior will also be supported (configurable) and you also will be able to specify matching patterns.

I hope this answers your question. Let me know you need further clarification.  

Kind regards,
Bob
the Telerik team

Posted by Community Admin on 16-May-2015 00:00

Hi,

This was what i was exactly looking for. But its still giving me the same error  :

 HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

 Is dynamic url possible in sitefinity. What is going wrong. I have been trying long for this. Even though i have added the code mentioned above, my user control is not getting triggered. Its throwing the error mentioned above.

Please help. 

Thanks,

Anju

Posted by Community Admin on 16-May-2015 00:00

You need to tell Sitefinity you are handling the dynamic URL otherwise it will throw a 404 (from 7.2 upwards)

 Just use RouteHelper.SetUrlParametersResolved(); somewhere in your widget and it won't 404.

This thread is closed