Copied to clipboard

Flag this post as spam?

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


  • Vasia Vasia 49 posts 241 karma points
    Oct 05, 2014 @ 04:28
    Vasia Vasia
    0

    Member login

    Hello,

    I have some protected pages and login form. After login I need to redirect to /home-protected/ or to page which was requested before. I was wondering how I can get return url?

    Umbraco v7

    Thanks, Oleg

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 05, 2014 @ 12:19
    Dennis Aaen
    0

    Hi Oleg,

    I think that you should have a look on this blogpost from the Umbraco Christmas calendar from 2012 about creating a Login form with Umbraco MVC SurfaceController by Jonas Eriksson

    http://24days.in/umbraco/2012/creating-a-login-form-with-umbraco-mvc-surfacecontroller/

    And here is a similar topic: http://our.umbraco.org/forum/using/ui-questions/57084-Redirect-after-login

    Hope this helps,

    /Dennis

  • Vasia Vasia 49 posts 241 karma points
    Oct 06, 2014 @ 06:14
    Vasia Vasia
    0

    Hi Dennis,

    Thanks. 

    If I go to /only-for-members/ page  I need to be redirected to this page after login.

    But if I go directly to /signin/ page  I need to be redirected to /home-protected/ page.

    So, I can do the following

    if Request.Url == /signin/ => Redirect("/home-protected/") 

    but

    if Request.Url != /signin/ => RedirectToCurentUmbracoUrl()

    I wonder if there is other way to do it.

    Thank you, Oleg

  • Damian Green 452 posts 1433 karma points
    Oct 08, 2014 @ 19:13
    Damian Green
    0

    hi Oleg,

    This is what i have on my login that stores the page they were visiting before redirected to the login page.

    var checkUrl = HttpContext.Current.Request.Url.AbsolutePath;
    
    @*// add a trailing / if there isn't one (you can access http://mydomain.com/login or http://mydomain.com/login/*@
    if (checkUrl[checkUrl.Length - 1] != '/')
    {
        checkUrl = checkUrl + "/";
    }
    
    @* if we dont have a session variable and have a request URL then store it *@
    @* we have to store it because if user tries an incorrect login then Current.Request.Url will show /umbraco/RenderMvc *@
    
    if (HttpContext.Current.Request.Url.AbsolutePath != "/umbraco/RenderMvc" &&
        HttpContext.Current.Session["redirectURL"] == null)
    {
        if (checkUrl != "/account/login/")
        {
            HttpContext.Current.Session["redirectURL"] = HttpContext.Current.Request.Url.ToString();
        }
    }
    
    
    if (User.Identity.IsAuthenticated)
    {
        var redirectUrl = (string) HttpContext.Current.Session["redirectURL"];
    
        if (!string.IsNullOrEmpty(redirectUrl))
        {                    
            // clear the session variable for future logins
            //
            HttpContext.Current.Session["redirectURL"] = null;
            HttpContext.Current.Response.Redirect(Model.Url == redirectUrl ? "/" : redirectUrl);
        }
        else
        {
            // Nothing in the session so we will go home
            HttpContext.Current.Response.Redirect("/");
        }
    }    
    

    Hope that helps you out.

    Damian

  • Biagio Paruolo 1594 posts 1825 karma points c-trib
    Aug 08, 2015 @ 16:30
    Biagio Paruolo
    0

    Do work it?

  • Biagio Paruolo 1594 posts 1825 karma points c-trib
    Aug 10, 2015 @ 07:10
    Biagio Paruolo
    0

    Solved.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @using System.Web.Mvc.Html
    @using ClientDependency.Core.Mvc
    @using Umbraco.Web
    @using Umbraco.Web.Models
    @using Umbraco.Web.Controllers
    
    
    
    @{
        var loginNodeID = 1207;
        var loginModel = new LoginModel();
        var loginStatusModel = Members.GetCurrentLoginStatus();
    
        loginModel.RedirectUrl = "/area-privata-b2b";
    
    
    
    }
    
    
    
    @using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
    {
    
    
                <h3 class="page-header">Login B2B</h3>  
                 @Html.ValidationSummary("loginModel", true)    
        <div>
    
                  <div class="form-group">
                    @Html.LabelFor(m => loginModel.Username)
            @Html.TextBoxFor(m => loginModel.Username, new { @placeholder = "Username", @class="form-control" })
            @Html.ValidationMessageFor(m => loginModel.Username)  
    
                  </div>
                  <div class="form-group">
                        @Html.LabelFor(m => loginModel.Password)
            @Html.PasswordFor(m => loginModel.Password, new { @placeholder = "Password", @class="form-control" })
            @Html.ValidationMessageFor(m => loginModel.Password)
                    </div>
                      @Html.HiddenFor(m => loginModel.RedirectUrl)
                   <button  class="btn btn-primary">Login</button>
                </div>  
    
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft