4

我已经在我的 Umbraco 应用程序 (v6) 中实现了一个 Surface 控制器,但是它不起作用。

这是简单的 Hello World 类:

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

不幸的是,每当我访问它时,都会收到 HTTP 404 错误。我尝试了以下网址:

  • /Umbraco/表面/我的
  • /Umbraco/表面/我的表面
  • /Umbraco/surface/mysurfacecontroller
  • /Umbraco/表面/我的/索引
  • /Umbraco/surface/mysurface/索引
  • /Umbraco/surface/mysurfacecontroller/index

我的 Global.asax 继承自 Umbraco.Web.UmbracoApplication

有没有人对我可能做错了什么有任何建议?

谢谢你

4

1 回答 1

1

A couple of things here:

You no longer need to end the name of you controller "SurfaceController", just inherit from SurfaceController.

Also you wouldn't need the path prefix /Umbraco/surface/, you should be able to access the Index() action just at /my/, if your controller was called the MyController.

Edit:

Assuming that you want to serve pages from your controller, you will need to amend the web.config AppSetting entry to include your controller's path

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

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

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

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

于 2013-08-28T10:36:32.380 回答