Copied to clipboard

Flag this post as spam?

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


  • Rob Scott 41 posts 94 karma points
    Aug 18, 2015 @ 18:35
    Rob Scott
    0

    SurfaceController Routing Error

    Umbraco v6. The SurfaceController methods were working, now they're not. The only thing that I did was clean the project/solution, and rebuild. None of the post methods are hitting. It seems like Umbraco routing is somehow messed up???

    After hitting submit button, I receive this error:

    There is not current PublishedContentRequest, it must be initialized before the RenderRouteHandler executes

    I've added breakpoints on all the methods in the SurfaceController (there are other forms as well), and none are hit.

    For example: Login

    /Views/Login.cshtml

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using ScottUmbracoCMS.Helpers
    
    @{
        Layout = "Master.cshtml";
    }
    
    @if (!Members.IsLoggedIn())
    {
        <div class="account-container">
            <div class="tab-content row">
                <div class="col-md-8">
                    <div id="ingresar" class="tab-pane fade in active">
                        @Html.Partial("/Views/Account/Login.cshtml", new ScottUmbracoCMS.Models.LoginCustomModel())
                    </div>
                    // .... other stuff omitted
    

    /Views/Account/Login.cshtml

    @model ScottUmbracoCMS.Models.LoginCustomModel
    @using ScottUmbracoCMS.Controllers
    
    @using (Html.BeginUmbracoForm<AccountSurfaceController>("Login"))
    {
        @Html.AntiForgeryToken()
        <div class="form-group hold-validation">
            <div class="control-container">
                @Html.TextBoxFor(x => x.Username,
                    new { placeholder = HttpUtility.HtmlDecode(Html.DisplayNameFor(x => x.Username).ToHtmlString()), @class = "form-control", @autocomplete = "off" })
            </div>
        </div>
        <div class="form-group">
            <div class="control-container">
                @Html.PasswordFor(x => x.Password,
              new { placeholder = HttpUtility.HtmlDecode(Html.DisplayNameFor(x => x.Password).ToHtmlString()), @class = "form-control", @autocomplete = "new-password" })
            </div>
        </div>
        @Html.ValidationMessage("loginModel")
        <footer class="center-text">
            <button type="submit" id="login-submit" class="button">Ingresar<span class="glyphicon glyphicon-ok"></span></button>
        </footer>
    }
    

    Controller

    public class AccountSurfaceController : SurfaceController
    {
        /// <summary>
        /// Handles login
        /// </summary>
        /// <param name="model">Umbraco Login model</param>
        /// <returns>redirects to home page</returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginCustomModel model)
        {
            if (ModelState.IsValid == false || !this.ValidateLogin(model.Username, model.Password))
            {
                return CurrentUmbracoPage();
            }
    
            Members.Login(model.Username, model.Password);
            FormsAuthentication.SetAuthCookie(model.Username, false);
    
            return Redirect("/");
        }
     }
    
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Aug 19, 2015 @ 05:55
    Dave Woestenborghs
    0

    Hi Rob,

    As you did a clean of your solution your bin folder has been emptied. If you installed any packages through the package installer the dll's of these packages would be removed as well.

    You can see what packages you have installed in the developer section. See if you have missing dll's of these packages.

    Dave

  • Rob Scott 41 posts 94 karma points
    Aug 19, 2015 @ 14:34
    Rob Scott
    0

    I fixed it, but I'll explain what happened, even though I don't understand WHY it happened.

    I created a SurfaceController w/ about 10 forms posting to it. I have a "Reset Password" functionality that emails a member w/ an encrypted string. This link that contains the encrypted string goes back to my website.

    For example:

    www.website.com/reset/HEWWEjsdflwerwerIEYRWRWEKnnzbnafsa

    I then hooked into Umbraco's ApplicationStarted event, and created a RouteConfig class,

      protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    

    RouteConfig Class

    public class RouteConfig
    {
        /// <summary>
        /// Registers the routes w/ Umbraco's routing engine
        /// </summary>
        /// <param name="routes">collection of routes</param>
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                "ForgotPasswordCheck",
                "reset/{query}",
                new
                {
                    controller = "ForgotPassword",
                    action = "ForgotPasswordCheck",
                    query = UrlParameter.Optional
                }
           );
        }
    }
    

    You can see in the above method, that the controller is NOW ForgotPassword. I used to have it as AccountSurface.

          controller = "AccountSurface",
          action = "ForgotPasswordCheck",
          query = UrlParameter.Optional
    

    So my forms were rending correctly, but when it would post to the AccountSurfaceController, nothing was coming through.

    Basically my question now is, why if I created a route that takes a totally different URL to the AccountSurfaceController, why does it crap out on all other form posts?

  • Rob Scott 41 posts 94 karma points
    Sep 01, 2015 @ 03:06
    Rob Scott
    0

    Anybody?

    The first issue is resolved, b/c I had custom routes. Going off of why this is an issue,

    why if I created a route that takes a totally different URL to the AccountSurfaceController, why does it crap out on all other form posts?

Please Sign in or register to post replies

Write your reply to:

Draft