Copied to clipboard

Flag this post as spam?

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


  • SlothMonkey 17 posts 56 karma points
    Feb 04, 2015 @ 10:57
    SlothMonkey
    0

    UmbLoginController page redirect

    I'm using the inbuilt umbraco log in controller to deal with the handling of signing users into my site.

    Nothing too strenuous and looks like this:

        @using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
    {
        <legend>Login</legend>
    
        @Html.ValidationSummary("loginModel", true)
    
        @Html.TextBoxFor(m => loginModel.Username, new { @class = "form-control", @placeholder = "Username" })
        @Html.ValidationMessageFor(m => loginModel.Username, "", new { @class = "alert-danger", @role = "alert" })
        <br />
    
        @Html.PasswordFor(m => loginModel.Password, new { @class = "form-control", @placeholder = "Password" })
        @Html.ValidationMessageFor(m => loginModel.Password, "", new { @class = "alert-danger", @role = "alert" })
        <br />
    
        <button class="btn btn-default">Login</button>
    }
    

    However, my login stuff is held on a separate page rather than on my home page. When the user logs in, I want to be able to redirect to my home page. Could someone please show me how I can do this?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 04, 2015 @ 12:13
    Jeroen Breuer
    0

    I think it's better to build your own LoginController in that case. Make your own controller and copy over from the soucecode: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/Controllers/UmbLoginController.cs

    Or if you look at the sourcecode you can also pass a RedirectUrl value. If you have a hidden input named RedirectUrl with the url as value that might also work.

    Jeroen

  • SlothMonkey 17 posts 56 karma points
    Feb 04, 2015 @ 14:35
    SlothMonkey
    0

    Thanks for the reply.

    I tried creating my own log in MVC but there is a lot functionality already built upon what I have already.

    Do you have any examples of how I could pass in that hidden value by any chance?

    This is all very new to me.

  • Vladimir Knobel 95 posts 171 karma points
    Apr 24, 2015 @ 12:10
    Vladimir Knobel
    0

    have a look on the "Login Status" snippet:

        @*
            Here you can specify a redirect URL for after logging out, by default umbraco will simply
            redirect to the current page. Example to redirect to the home page:
    
            logoutModel.RedirectUrl = "/"; 
        *@ 
    
    @Html.HiddenFor(m => logoutModel.RedirectUrl)
    
  • Jamie Attwood 201 posts 493 karma points c-trib
    Oct 08, 2015 @ 15:52
    Jamie Attwood
    2

    To elaborate on Vlax's note, you can add this under the login model declaration:

    var loginModel = new LoginModel();

    loginModel.RedirectUrl = "/your-redirect-url/";

    Then inside the form add this:

    @Html.HiddenFor(m => loginModel.RedirectUrl)

    That's it....

    Cheers,

    Jamie

  • AJS 31 posts 212 karma points
    May 03, 2016 @ 22:29
    AJS
    101

    This is all I needed. Thank you thank you thank you!

    For anyone who is interested, here is my Partial View Macro for Login (with my own HTML and CSS markup that would need to be changed)

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
    @using System.Web.Mvc.Html
    @using ClientDependency.Core.Mvc
    @using Umbraco.Web
    @using Umbraco.Web.Models
    @using Umbraco.Web.Controllers
    
    @{
    
        var loginModel = new LoginModel();
        loginModel.RedirectUrl = "/members-area/";
    
        Html.EnableClientValidation();
        Html.EnableUnobtrusiveJavaScript();
        Html.RequiresJs("/umbraco_client/ui/jquery.js");
        Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
        Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
    }
    
    @* NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed *@
    @Html.RenderJsHere()
    
    
    @using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
    {
        <fieldset>
            <legend class="hidden-xs-up">Login</legend>
    
            @Html.ValidationSummary("loginModel", true)
    
                <div class="form-group logmein">
                    @Html.TextBoxFor(m => loginModel.Username, new { @placeholder = "Username" })
                    @Html.ValidationMessageFor(m => loginModel.Username)
                </div>
                <div class="form-group logmein">
                    @Html.PasswordFor(m => loginModel.Password, new { @placeholder = "Password" })
                    @Html.ValidationMessageFor(m => loginModel.Password)
                </div>
                <button class="btn btn-primary">Sign in</button>
    
        </fieldset>  
    
        @Html.HiddenFor(m => loginModel.RedirectUrl)
    }
    
  • Carlos Mosqueda 240 posts 431 karma points
    Apr 02, 2018 @ 23:44
    Carlos Mosqueda
    0

    Beautiful. Thank you for sharing, this is awesome and very easy.

Please Sign in or register to post replies

Write your reply to:

Draft