Copied to clipboard

Flag this post as spam?

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


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 07, 2016 @ 16:21
    Michaël Vanbrabandt
    0

    Redirect to another page when Member is curently logged in and tries to access the login page

    Hi,

    I have a document type called Login which is a page that contains a login form for our members.

    What I am trying to do is, when a member that is already logged in and access the login page he gets redirected to another page.

    How can I accomplish this?

    /Michael

  • Dennis Adolfi 1082 posts 6448 karma points MVP 6x c-trib
    Mar 08, 2016 @ 07:16
    Dennis Adolfi
    100

    Add this to the top of your Login macro partial, of just the same template as the login form:

        var anotherPageId = 1222;
    
        var loginStatusModel = Members.GetCurrentLoginStatus();
    
        if (loginStatusModel.IsLoggedIn)
        {
            Response.Redirect(new DynamicNode(anotherPageId).Url);
        }
    

    But you should probobly fetch the "anotherPageId" dynamicly and not hardcode it like i did, but this is just an example.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 11, 2016 @ 10:59
    Michaël Vanbrabandt
    0

    Hi Dennis,

    thanks for the reply.

    Can't you use the RedirectToUmbracoPage ?

    /Michael

  • Dennis Adolfi 1082 posts 6448 karma points MVP 6x c-trib
    Mar 11, 2016 @ 11:06
    Dennis Adolfi
    0

    I dont know actually, i just copied this code snippet from an old project i built a while back. Im not sure if RedirectToUmbracoPage works in the header or if it only works in a controller.

    Try and see, but the code in the previous post does the same thing. And you know what they say: "If it ain´t broke..." :)

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 11, 2016 @ 13:04
    Michaël Vanbrabandt
    0

    Hi Dennis,

    I used your code but I get the following exception:

    {"Server cannot append header after HTTP headers have been sent."}

    I have tried placed your code on top of the view and by creating a custom controller for the login document type but both give me the same result.

    What am I missing here??

    /Michael

  • Dennis Adolfi 1082 posts 6448 karma points MVP 6x c-trib
    Mar 11, 2016 @ 13:07
    Dennis Adolfi
    0

    Strange, works for me. Can you show your code?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 11, 2016 @ 13:13
    Michaël Vanbrabandt
    1

    Here is the code using razor in my login.cshtml view page:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Login>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
    Layout = "Master.cshtml";
    
    
    var myProsecPage = CurrentPage.Site().Descendants("myProsec").Where("Visible").FirstOrDefault();
    
    var loginState = Members.GetCurrentLoginStatus();
    
    if(loginState.IsLoggedIn)
    {
        Response.Redirect(myProsecPage.Url);
    }
    
    }
    
    <!-- Begin .page-heading -->
    <section class="page-heading parallax parallax-1 no-shadow">
    
    </section><!-- End .page-heading -->
    
    <!-- Begin .page-content -->
    <section class="page-content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-no-padding">
                <div class="inner">
    
                    <div class="row">
                        <div class="col-lg-5">
    
                            <h2 data-animate="fadeInUp" data-animate-delay="0.4">Aanmelden bij Mijn Prosec</h2>
    
                            @Html.Action("Login", "AccountSurface", new { inline = true })
    
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    </section><!-- End .page-content -->
    
  • Dennis Adolfi 1082 posts 6448 karma points MVP 6x c-trib
    Mar 11, 2016 @ 13:20
  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 11, 2016 @ 13:25
    Michaël Vanbrabandt
    1

    Dennis,

    using this it works.

    Thanks!

    /Michael

  • Dennis Adolfi 1082 posts 6448 karma points MVP 6x c-trib
    Mar 11, 2016 @ 13:36
    Dennis Adolfi
    0

    Awsome, great to hear that is worked out for you! :)

    Have a great weekend!!

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Mar 11, 2016 @ 13:50
    Paul Wright (suedeapple)
    0

    Make Umbraco do less un-needy traversing of the tree :-)

    var loginState = Members.GetCurrentLoginStatus();
    
    if(loginState.IsLoggedIn)
    {
    var myProsecPage = CurrentPage.Site().Descendants("myProsec").Where("Visible").FirstOrDefault();
        Response.Redirect(myProsecPage.Url);
    Response.End;
    }
    
  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 11, 2016 @ 13:54
    Michaël Vanbrabandt
    0

    Thanks for the headsup!

    /Michael

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Mar 11, 2016 @ 14:02
    Paul Wright (suedeapple)
    0

    You might want to check if myProsecPage is not null as well...

    This snippet will check if its null, and if it is, we'll redirect to the homepage instead...

    Response.Redirect(myProsecPage =! null ? myProsecPage.Url : "/");
    
Please Sign in or register to post replies

Write your reply to:

Draft