Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim C 146 posts 502 karma points
    Sep 27, 2016 @ 15:39
    Tim C
    0

    Creating a surface controller

    I am trying to create a test SurfaceController and view in Umbraco 7. Following the details in the documentation

    I think I need to create a plugin controller.

    I have created a very simple one and put the controller in an area ie

    /Umbraco/TimCDev/timCTest.cs
    

    I have put the corresponding view

    /Umbraco/App_Plugins/Views/Shared/timCTest.cshtml
    

    I then forced Umbraco to recompile by editing and saving web.config (I am using a hosted version of Umbraco, so don't have a VIsual Studio project).

    I then browsed to (domain)/Umbraco/TimCDev/timCTest

    and get the following error

    Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

    Have I done something wrong, or is this a config change needed?

    My controller, by the way is

    using System.Web.Mvc;
    using Umbraco.Web.Mvc;
    using Umbraco.Web.Mvc.SurfaceController
    
    
    [PluginController("TimCDev")]
        public class timCTestController : Umbraco.Web.Mvc.SurfaceController
        {       
    
            public ActionResult Index()
            {
                return Content("Just a test");
            }
        }
    
  • Alex Skrypnyk 5397 posts 19981 karma points MVP 3x admin c-trib
    Sep 27, 2016 @ 16:37
    Alex Skrypnyk
    0

    Hi Tim,

    First of all, please, place your timCTest.cs file to App_Code folder. Read more - https://msdn.microsoft.com/en-us/library/t990ks23.aspx

    This is only place where you can put .cs files without compiling it to dlls.

    Next - ask again, we will help you with pleasure.

    Thanks,

    Alex

  • Alex Skrypnyk 5397 posts 19981 karma points MVP 3x admin c-trib
    Oct 03, 2016 @ 09:13
    Alex Skrypnyk
    0

    Hi Tim,

    Did you solve issue?

    Can you share your experiece?

    Thanks,

    Alex

  • Tim C 146 posts 502 karma points
    Oct 14, 2016 @ 15:04
    Tim C
    0

    Alex

    Sorry for delay, got sidetracked with other projects non Umbaco ;-(

    I put the cs files but when I browse to it

    www.mydomain.com/timctest

    I get a 404 error.

    Do I need to set up some routing?

  • Alex Skrypnyk 5397 posts 19981 karma points MVP 3x admin c-trib
    Oct 14, 2016 @ 15:24
    Alex Skrypnyk
    0

    Hi Tim,

    SurfaceControllers are routing by default table, so yes, you have to create route for it.

  • David Brendel 753 posts 2820 karma points c-trib
    Oct 14, 2016 @ 21:33
    David Brendel
    0

    Hi Tim,

    moving the cs file to App_Code was correct. But I think the url you call is not.

    When using the PluginController attribute the routing is used like an mvc area. Think it should be mydomain.com/TimCDev/timCTest/.

    Maybe try that.

    Regards David

Please Sign in or register to post replies

Write your reply to:

Draft