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

Forums / Developing with Sitefinity / Issue with URL Rewriter

Issue with URL Rewriter

6 posts, 0 answered
  1. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    25 Jul 2007
    Link to this post
    Hi,

    Using Sitefinity's url rewriter function works great except postbacks to the page fail because the parameter is in the postback url twice. Here is the scenario:

    I am using it for a product page to write the url /product/sku.aspx to /product.aspx?n=sku

    It is working and returns the product on the product.aspx page based on the sku code used in the  url but when but I have a button on the products page for example which do a post back to the page i get an error.

    Here's why - to do its stuff the button tries to post back to the url /product/sku.aspx?n=sku instead of just /product/sku.aspx

    This then throws and error because the page being called has 2 parameters with the value n in the url and I can't figure out how to stop the button from chucking the n= on the back of the url it needs to post back to do its stuff.

    Do you follow?

    Thanks

    Seth
  2. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    25 Jul 2007
    Link to this post
    Hi Seth Cleaver,

    To clear the query string on page postback you should add code similar to the one bellow in the master page code behind:

    protected override void OnLoad(EventArgs e)  
    {  
        base.OnLoad(e);  
        this.form1.AddKeysToRemove(new string[] { "myKey" });  

    This is needed as you must notify the CmsForm (the override of the standard form control) to remove keys from the query string in the action attrebute. In this case the key to remove is myKey and the CmsForm is this.form1

    Note that the use of CmsForm will be depreciated in the upcoming version as it has some serious disadvantages. We are introducing new approach in version 3.1.

    Regards,
    Vassil Daskalov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    09 Oct 2007
    Link to this post
    Hi,

    Now that I have upgraded the site to 3.1 what do I need to do with this code so that the query string is cleared on postaback?

    The Onload method you supplied no longer works with the removal of the CmsForm tag from 3.0.

    Do I no longer need the code below?

    It appears that on removing the Onload code the pages now function without it yet the page is still tries to post back to the url /product/sku.aspx?n=sku instead of just /product/sku.aspx

    Thanks

    Seth
  4. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    09 Oct 2007
    Link to this post
    Hi Seth Cleaver,

    In order to be able to remove query keys from the url, your page should inherit from CmsPageBase class which in its turn inherits from the Page class. This time you should overwrite your OnLoad event like this:

    protected override void OnLoad(EventArgs e)  
    {  
        if (Request.QueryString["myKey"] != null)  
            base.AddKeysToRemove("myKey");  
        base.OnLoad(e);  

    This is needed because we no longer use the cms form, but a form adapter instead.

    Greetings,
    Vassil Daskalov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    09 Oct 2007
    Link to this post
    Hi,

    Thanks for that. I am doing this in a master page and if I inhert from theCmsBasPage as pointed out I of course get and error becuase it tis a masterpage not actually a page.

    I am doing it like this:

    public partial class App_Master_Funky_Friends_Default : Telerik.Cms.Web.CmsPageBase


    Thanks

    Seth
  6. Bob
    Bob avatar
    330 posts
    Registered:
    30 Dec 2016
    09 Oct 2007
    Link to this post
    Hey Seth,

    You do not need to inherit from CmsPageBase for Sitefinity internal pages as they already inherit from that class. All you need to do is to cast the Page of your control or master page to CmsPageBase and add the keys.

    protected override void OnLoad(EventArgs e)  
    {  
        CmsPageBase cmsPage = this.Page as CmsPageBase;  
        if (cmsPage != null)  
            cmsPage.AddKeysToRemove("MyKey");  
        base.OnLoad(e);  


    Greetings,
    Bob
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
6 posts, 0 answered