Copied to clipboard

Flag this post as spam?

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


  • Kenneth Jakobsen 67 posts 203 karma points hq
    Oct 06, 2016 @ 13:20
    Kenneth Jakobsen
    0

    Redirect to Action from within controller

    Hi I'm having a curious problem I have a Controller called "CallbackController" it inherits : RenderMvcController and has no View as all it does is redirect to a another action on the same controller.

    I Use RedirectToChildAction, but when I do the I get thi YSOD "No route in the route table matches the supplied values." error, I definitely doing something wrong, but I cant figure out what.

    public class SignInCallbackController : RenderMvcController
    {
        private readonly IManageAuthentication _authentication;
    
        public SignInCallbackController(IManageAuthentication authentication)
        {
            _authentication = authentication;
        }
    
        // GET: MemberLogin
        public async Task<ActionResult> Index()
        {
            var code = Request["code"];
            var state = Request["state"];
            var error = Request["error"] ?? string.Empty;
    
            var response = await _authentication.GetResponse(code, state, error);
            return RedirectToAction("LoggedIn", "SignInCallback");
        }
        [ChildActionOnly]
        [Authorize]
        public ActionResult LoggedIn(RenderModel model)
        {
            return View();
        }
    }
    

    Any thoughts?

  • Kenneth Jakobsen 67 posts 203 karma points hq
    Oct 07, 2016 @ 06:39
    Kenneth Jakobsen
    0

    I Would really like to do this without having to create a document

  • Micha Somers 134 posts 597 karma points
    Oct 07, 2016 @ 11:56
    Micha Somers
    0

    Async methods with an RenderMVCController have not been a happy couple. General approach would be not to call the Index() action at all and make your actions async by targeting the template’s action which take precedence over the default Index action.

    To do this without a document might make it even harder.

    Still, the following links provide information and explain several workarounds.

    http://www.digbyswift.com/blog/2015/10/asyncawait-in-umbraco-custom-controllers/

    https://our.umbraco.org/forum/developers/extending-umbraco/66777-implementing-an-async-custom-controller-in-umbraco-7

    https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/64076-Async-RenderMvcController

    https://our.umbraco.org/forum/developers/api-questions/75388-async-form-post-throws-exception

  • Kenneth Jakobsen 67 posts 203 karma points hq
    Oct 07, 2016 @ 12:40
    Kenneth Jakobsen
    0

    Actually the Async index works perfectly fine, its the LoggedIn action that is not working. Index has a document though.

  • Micha Somers 134 posts 597 karma points
    Oct 07, 2016 @ 18:35
    Micha Somers
    0

    In that case, it looks like the ChildActionOnly or Authorize attribute is preventing you from accessing it.

    In order to check if the routing itself is working correctly, could you temporarily remove the ChildActionOnly attribute in order to see if your LoggedIn action will be called. If that doesn't work, try also removing the Authorize attribute. (I know ... it's ugly but it's only temporarily)

    In case it is being called succesfully, the next step will be to find out how the attributes can be used successfully or search for a workaround for that.

    Further, you say that Index has a document. Do you mean by that, that you have a document type (named SignInCallback) that does have a template? If it has a template, what's the name of that template?

    If it's named LoggedIn, I would expect the LoggedIn action of the controller to be accessible via default Umbraco routing.

    If it's not named LoggedIn and/or you don't want a template, you probably need to define a ContentFinder ( https://our.umbraco.org/documentation/reference/routing/request-pipeline/IContentFinder ) but that would mean you need somewhere a node to be available to map to.

  • Kenneth Jakobsen 67 posts 203 karma points hq
    Oct 10, 2016 @ 13:38
    Kenneth Jakobsen
    1

    I Ended up using a node anyways, but i'm not really liking that i have to create documents for somethin in umbraco that the user is not supposed to see

  • Micha Somers 134 posts 597 karma points
    Oct 10, 2016 @ 14:42
    Micha Somers
    0

    Hi Kenneth,

    It does indeed not feel right to have to create a document if that document has no use at all.

    What I do not understand yet is what you would like the LoggedIn method to return. If I understand you correctly it returns something that you do not want to be managed by Umbraco. (Otherwise, if that content would be managed within the Umbraco pipeline, a node would make sense ... right?)

    Still, it would surprise me if it cannot be solved in a more sensible way.

    Have you considered using a user defined route?

    If not, please have a look at: https://our.umbraco.org/documentation/Reference/Routing/custom-routes.

    Further, there's also something called a UmbracoVirtualNodeRouteHandler that could lead to an appropiate solution.

Please Sign in or register to post replies

Write your reply to:

Draft