Classic Mode MVC Routing

Posted by Community Admin on 04-Aug-2018 20:24

Classic Mode MVC Routing

All Replies

Posted by Community Admin on 01-May-2014 00:00

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

Posted by Community Admin on 05-May-2014 00:00

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

Posted by Community Admin on 06-May-2014 00:00

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
 

Posted by Community Admin on 06-May-2014 00:00

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

Posted by Community Admin on 06-May-2014 00:00

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
 

This thread is closed