Copied to clipboard

Flag this post as spam?

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


  • Alexander Mounzer 8 posts 118 karma points
    Jul 15, 2021 @ 11:06
    Alexander Mounzer
    0

    How do you redirect to another Page from a RenderMVCController

    Hi everyone!

    I'm still learning umbraco and I am having the issue of Redirecting my users to different pages generated in umbraco when they login.

    I've tried to use return redirect(), return CurrentTemplate and RedirectToRoute

    This is my controller:

    public class MinaSidorController : RenderMvcController
    {
        IMapper _mapper;
        IAuthenticationService _authenticationService;
        IBookshelfService _bookshelfService;
        public MinaSidorController(IAuthenticationService authenticationService, IBookshelfService bookshelf, IMapper mapper)
        {
            _authenticationService = authenticationService;
            _bookshelfService = bookshelf;
            _mapper = mapper;
        }
    
        // GET: MinaSidor
        [HttpGet]
        public async Task<ActionResult> Index(ContentModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                var ticket = (string)Session["ticketkey"];
                var viewModel = new LoginViewModel();
                var testkey = ConfigurationManager.AppSettings["SITEKEY"];
                try
                {
                    var response = await _authenticationService.GetUserInfo(testkey, ticket, true);
                    var bookshelfResponse = await _bookshelfService.GetBookshelf(ticket);
                    viewModel.UserInformationModel = response;
                    viewModel.Shelf = bookshelfResponse;
                }
                catch (Exception e)
                {
                    return RedirectToAction("Login", "Authentication");
                }
    
                switch (viewModel.UserInformationModel.userRole)
                {
                    case "Patron":
                        return CurrentTemplate(viewModel);
                    case "Registrator":
                        return CurrentTemplate(viewModel);
                    case "Minor Patron":
                        return CurrentTemplate(viewModel);
                    case "Supplier":
                        return CurrentTemplate(viewModel);
                    default:
                        return CurrentTemplate(viewModel);
                }
            }
            else
            {
                return RedirectToAction("Login", "Authentication");
            }
        }
    

    And these are the pages I have created in the backoffice:

    From backoffice

    Vuxen = Patron, Registrator = Bibliotekarie.

    Does anyone know how to redirect my Login Action to these pages?

  • Huw Reddick 1932 posts 6722 karma points MVP 3x c-trib
    Jul 27, 2021 @ 15:39
    Huw Reddick
    100

    You should be able to do something like

    var redirectPage = Umbraco.Content(123); //page id here
    
    return Redirect(redirectPage.Url);
    
  • 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