Umbraco surface controller inside project v6

I applied a surface controller in my Umbraco (v6) application, however it does not work.

Here is a simple Hello World class:

public class MySurfaceController : Umbraco.Web.Mvc.SurfaceController { [HttpGet] public ActionResult Index() { return Content("hello world"); } } 

Unfortunately, when I access it, I get an HTTP 404 error. I tried to use the following URLs:

  • / Umbraco / surface / mine
  • / Umbraco / surface / mysurface
  • / Umbraco / surface / mysurfacecontroller
  • / Umbraco / surface / mine / index
  • / Umbraco / surface / mysurface / index
  • / Umbraco / surface / mysurfacecontroller / index

My Global.asax inherits from Umbraco.Web.UmbracoApplication

Does anyone have any suggestions as to what I might be doing wrong?

Thank you

+4
source share
1 answer

A few things here:

You no longer need to end your SurfaceController controller name, just inherit from SurfaceController .

Also, you do not need the path prefix /Umbraco/surface/ , you should only have access to the Index () action in /my/ if your controller was called by MyController .

Edit:

Assuming you want to serve pages from your controller, you need to make changes to the AppSetting entry in web.config to include the path to the controller.

 <add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/my" /> 

You will also need to register a route specifically for your controller from global.asax:

 routes.MapRoute( name: "Default", url: "my/{action}/{id}", defaults: new { action = "Index", id = UrlParameter.Optional } ); 

It is important that this is specific to your controller, as you do not want it to override any Umbraco routing.

+1
source

Source: https://habr.com/ru/post/1499325/


All Articles