简体   繁体   中英

Route Hijacking in umbraco 7

I'm trying to set up route hijacking on Umbraco 7 with little success. I have a view called Home.cshtml , the top few lines of which are:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = "Master.cshtml";
}

I added a controller:

-EDIT- updated question to include Index() controller action.

namespace CLIAUmbraco7.Controllers
{
    public class HomeController : Umbraco.Web.Mvc.RenderMvcController
    {
        public override ActionResult Index(RenderModel model)
        {
            string country = "";

            return base.Index(model);
        }
        public ActionResult Index()
        {
            return View();
        }     
    }

Sticking a breakpoint on the Layout line catches the site before it loads but HomeController is never called. Any idea what I'm doing wrong?

You are missing an Index() controller action. Your controller should look like this:

public class HomeController : Umbraco.Web.Mvc.RenderMvcController
{
    public override ActionResult Index(RenderModel model)
    {
        //Do some stuff here, then return the base method
        return base.Index(model);
    }

}

Take a look at the article on Umbraco website .

By default the controller needs to be called

[TheDocumentType Alias YouWantToHijack]Controller

If your document type is not "Home" then it will not be intercepted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM