Copied to clipboard

Flag this post as spam?

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


  • Adam Jenkin 71 posts 226 karma points
    Mar 21, 2013 @ 12:30
    Adam Jenkin
    0

    Possible bug with razor forms and routing

    I believe I had found a bug in contour in umbraco v 4.8.

    This issues follows one raised here:

    http://our.umbraco.org/forum/umbraco-pro/contour/38943-Error-Service-Endpoint-not-found-on-submit

     

    When an umbraco website uses routing (in web.config)

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>  

    and a route is registered on application start up (like this in app_code) .. 

    using System.ServiceModel.Activation;
    using System.Web.Routing;
    using umbraco.BusinessLogic;
    using Umbraco.Web;
    using Umbraco.Core;
    public class AddRouteTest : IApplicationEventHandler
    {
        private static object _lockObj = new object();
        private static bool _ran = false;
        public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
        {
            // lock
            if (!_ran) {
                lock (_lockObj) {
                    if (!_ran) {
                        RouteTable.Routes.Add(new ServiceRoute("my/custom/route", new WebScriptServiceHostFactory(), typeof(object)));
                        _ran = true;
                    }
                }
            }
        }
    public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext) {}
    public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext) {}
    }

    .. the <form> tag rendered on a form (using the razor macro ) is added incorrectly like this:

    <form action="/my/custom/route?action=ContourForm&amp;controller=FormRender" enctype="multipart/form-data" method="post">

    I think I have found a solution which is to modify the umbraco\plugins\umbracoContour\views\form.cshtml to render the form tag differently (from line 25)

    @* ** THIS BREAKS** using (Html.BeginForm("ContourForm", "FormRender", FormMethod.Post, new { enctype = "multipart/form-data" })) ** SO USE INSTEAD ** *@
    @using (Html.BeginForm())

     

     

     

    Is this a bug with contour? A known issue that routing cannot be used on umbraco sites? or am I registering my custom route incorrectly?

    Adam

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies