Copied to clipboard

Flag this post as spam?

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


  • Osman Coskun 170 posts 404 karma points
    Apr 20, 2021 @ 12:41
    Osman Coskun
    0

    How to get the node id of a protected page

    Hi all,

    Is it possible to get the id of a protected page in the member login page? I need it to pass to the controller to redirect to protected page after successful login.

    Thanks...

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 20, 2021 @ 13:44
    Alex Skrypnyk
    0

    Hi Osman

    You can get the node id as usual page, protected pages mean that members are not able to visit the page if their access is restricted.

    Thanks,

    Alex

  • Osman Coskun 170 posts 404 karma points
    Jun 02, 2021 @ 11:11
    Osman Coskun
    0

    Hi Alex,

    Sorry for replying late, I've to work on an urgent project.

    I'm using the following code to check if a member is approved prior to login, then redirect to protected page if login succeeded. Login form works fine if the email and pass entered correctly. If the user makes typo in email or pass and tries with correct entries in second try i get the error:

    [NullReferenceException: There is no current PublishedRequest, it must be initialized before the RenderRouteHandler executes]

       Umbraco.Web.Mvc.RenderRouteHandler.GetHttpHandler(RequestContext requestContext) in D:\a\1\s\src\Umbraco.Web\Mvc\RenderRouteHandler.cs:66
       System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +174
       System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +201
       System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +132
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73
    

    Here is the code i use in MVC login controller:

    public ActionResult MvcMemberLoginPost(MvcMemberLoginModel model)
            {
                if (model.Eposta != null && model.Sifre != null)
                {
    
    
    
                    var memberService = Services.MemberService;
                    var member = memberService.GetByEmail(model.Eposta);
    
                    string membersLoginUrl = HttpContext.Session["loginUrl"].ToString().ToLower();
                    string checkUrl = HttpContext.Session["checkUrl"].ToString().ToLower();
    
                    if (member != null && model.Sifre != null)
                    {
                        if (!member.IsApproved)
                        {
                            TempData["Status"] = Umbraco.GetDictionaryValue("ValidateFirst");
                            return RedirectToCurrentUmbracoPage();
                        }
    
                        if (Members.Login(model.Eposta, model.Sifre))
                        {
                            FormsAuthentication.SetAuthCookie(model.Eposta, model.RememberMe);
                            if (checkUrl != membersLoginUrl)
                            {
                                var ses = checkUrl;
                                HttpContext.Session["checkUrl"] = null;
                                HttpContext.Session["loginUrl"] = null;
                                return Redirect(ses);
                                // If i use following line it works fine
                                //return RedirectToUmbracoPage(1227);
                            }
                            else
                            {
                                return Redirect("/");
                            }
                        }
                        else
                        {
                            TempData["Status"] = Utils.GetDictionaryItem("MvcMemberLogin.LoginInvalid");
                            return CurrentUmbracoPage();
                        }
                    }
                    else
                    {
                        TempData["Status"] = Utils.GetDictionaryItem("MvcMemberLogin.LoginInvalid"); 
                        return CurrentUmbracoPage();
                    }
                }
                else
                {
                    return CurrentUmbracoPage();
                }
            }
    

    If i use return RedirectToUmbracoPage(Id) for after succesfull login it works, that's why i need to pass the id of protected page to login view.

    Best regards, Osman

Please Sign in or register to post replies

Write your reply to:

Draft