Copied to clipboard

Flag this post as spam?

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


  • Anton Oosthuizen 206 posts 486 karma points
    Dec 03, 2015 @ 15:32
    Anton Oosthuizen
    0

    SurfaceController 404 on post but not on get

    Please advise

    /umbraco/surface/MyUmbReset/test/ <- this works fine /umbraco/surface/MyUmbReset/testpost <- returns a 404 /umbraco/surface/MyUmbReset/testpostid/1 <- returns a 404

    using System.Web.Mvc;
    using umbraco.cms.businesslogic.member;
    using Umbraco.Web.Models;
    using Umbraco.Web.Mvc;
    using Umbraco.Core;
    using System;
    using umbraco;
    using Umbraco.Core.Services;
    using Umbraco.Core.Security;
    using System.Web;
    
    namespace Surfacecontrollers
    {
        public class MyUmbResetController : SurfaceController
        {
    
            [HttpGet]
            public ActionResult test()
            {
    
    
                return Content("Hi there!");
    
            }
            [HttpPost]
            public ActionResult testpost()
            {
    
    
                return Content("posted");
    
            } public ActionResult testpostid(string id)
            {
    
    
                return Content(id);
    
            }
    
  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Dec 03, 2015 @ 21:46
    Marc Goodson
    0

    Hi Anton

    I've just cut and paste the code you have above into a surface controller in an Umbraco site on my machine, and all appears to work ok!; but how are you 'posting' to the testpost endpoint ?

    Are you using BeginUmbracoForm ?

    eg in my test version of your code I have:

    @using (Html.BeginUmbracoForm("testpost", "MyUmbReset"))
    {
        <button type="submit">Go</button>
    }
    

    in the view to generate the form, that posts to your 'testpost' endpoint.

    If you use a straightforward form tag or use Html.BeginForm, then I think the post request will be missing the hidden 'ufprt' value that Umbraco routing looks for in Surface Controller posts:

    <input name="ufprt" type="hidden" value="C9ABB34A74187D71E1C422AB3F1436F8F1445782742DBF55FF39CBEA305791A84CB02E5A258A139C77DD6AAF0F117700AFA7C851289199DCACC6128F6461728694E6963CC2B54B08C171CB94212BDB8D33F1133F59C4A8484EA80F8EAEB1E0418963F35119404769471B2076B709E9C34F993FE50DE42F2F208181EF2BDC1982D4566029A114E62BD880188927B3C400">
    

    which is a hash of the routing values.

Please Sign in or register to post replies

Write your reply to:

Draft