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

Forums / Developing with Sitefinity / Classic Mode MVC Routing

Classic Mode MVC Routing

5 posts, 0 answered
  1. Mike
    Mike avatar
    12 posts
    Registered:
    07 Mar 2014
    01 May 2014
    Link to this post

    Hello, I am new to SiteFinity and I am looking to build out a new site in Classic MVC mode. I want to leverage all of the SiteFinity content creation & management, workflows, etc., but I need very tight control over the markup and it needs to be easily accessible, like in a standard MVC project.  Based on what I've been able to find, this seems pretty straightforward aside from a couple routing issues.

     The issue I am having now is that I want all pages to be in classic mode and I want the initial page to accessible via the site root (example: "http://www.example.com/" should drive to my controller & view), instead it appears that the site index page is being captured by the SiteFinity routes.  Is there any way to get my classic MVC route to be picked up as the index of the site?

     Thanks

  2. Mike
    Mike avatar
    12 posts
    Registered:
    07 Mar 2014
    05 May 2014
    Link to this post

    Anyone?

    Is there any way to insert a default route into the SiteFinity route table, so that I could have the default root of the site (e.g. - "http://www.example.com") point to my custom controller and views?  This has to be available somewhere.

    Thanks

  3. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    06 May 2014
    Link to this post
    Hello Mike,

    This could be done by registering the MVC controller under root of the project:
    Bootstrapper.MVC.MapRoute(
           "Classic",
           "{action}/{id}",
           new { controller = "MyMvc", action = "Index", id = (string)null }
       );
    However, the home page will be still overriden by Sitefinity, so I suggest you make a redirect to yoursite.com/index, which will load the Index action of your Controller and return your 'home page'
     view.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  4. Mike
    Mike avatar
    12 posts
    Registered:
    07 Mar 2014
    06 May 2014
    Link to this post

    Ok, thanks for the reply.  How exactly would I add this redirect to override the default sitefinity homepage?

  5. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    06 May 2014
    Link to this post
    Hello Mike,

    You have several options to achieve this.
    1. You can make a custom widget, which will redirect to the controller's action and place it on the home page.
    2. Attach to the begin request event of the bootstrapper and redirect, for example:
    protected void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs args)
            {
                if (args.CommandName == "Bootstrapped")
                {
                    this.BeginRequest += new EventHandler(Application_BeginRequest); 
                }
            }
     
            protected void Application_BeginRequest(object sender, EventArgs e)
            {
                if (Request.Url.ToString() == "http://mysite/")
                {
                   Response.StatusCode = 301;
                   Response.Redirect("http://mysite/index");
                }
            }

    3. Make a url rewrite and redirect to the page if the patter is matching.


    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
5 posts, 0 answered