Copied to clipboard

Flag this post as spam?

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


  • Bear 40 posts 129 karma points
    May 23, 2014 @ 17:46
    Bear
    0

    "HandleLogout" gives me a YSOD

    Can anyone tell me why I'm getting a YSOD from the following code? It's only happening when I click the "Logout" button.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @using Umbraco.Web
    @using Umbraco.Web.Controllers
    
    @if (Members.IsLoggedIn())
    {
        <p>You are currently logged in as <strong>@HttpContext.Current.User.Identity.Name</strong></p>
    
        using (Html.BeginUmbracoForm<UmbLoginStatusController>("HandleLogout"))
        {
        <fieldset>
            <legend>Logout</legend>
            <button>Logout</button>
        </fieldset>
        }   
    }
    else
    {
        <p>You are not logged in.</p>
    }
    

    Clicking the "Logout" button

    [NullReferenceException: Object reference not set to an instance of an object.]
       Umbraco.Web.Controllers.UmbLoginStatusController.HandleLogout(PostRedirectModel model) +130
       lambda_method(Closure , ControllerBase , Object[] ) +93
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +260
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +38
       System.Web.Mvc.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10() +123
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +855266
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +855266
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +855266
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +855266
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +309
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +855200
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__19() +40
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +15
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
    

    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 24, 2014 @ 11:48
    Jan Skovgaard
    0

    Hi Bear

    What does your code for logging members out look like?

    And what version of Umbraco are you using?

    /Jan

  • Bear 40 posts 129 karma points
    May 24, 2014 @ 12:03
    Bear
    0

    Hi Jan,

    7.1.3 - I'm using the "snippets" from the macro section, so it's using the UmbLoginStatusController which is already in Core. That means it's using this code;

    https://github.com/umbraco/Umbraco-CMS/blob/7.1.4/src/Umbraco.Web/Controllers/UmbLoginStatusController.cs

    I'm very aware of how to roll my own, but I wanted to see if I could just get this working "out-of-the-box" so a designer could just cut and paste.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 24, 2014 @ 15:54
    Jan Skovgaard
    0

    Hi Bear

    Aaah ok - Hmm, not sure wether that's actually a bug or not to be honest. Have not yet had the time to play around with these myself yet.

    I guess it could not hurt to file it on the issue tracker

    /Jan

  • Lennart Stoop 304 posts 842 karma points
    Jun 11, 2014 @ 15:33
    Lennart Stoop
    0

    Hi guys,

    I just ran into the same problem, and it seems the model is not bound (hence the null reference exception).

    As a simple workaround you can just create a PostRedirectModel in the view, and make sure it is bound to the form context.

    @{
    
    var logoutModel = new PostRedirectModel();
    logoutModel.RedirectUrl = "/";
    
    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");
    }
    
    @using (Html.BeginUmbracoForm<UmbLoginStatusController>("HandleLogout"))
    {
        @Html.HiddenFor(m => logoutModel.RedirectUrl)
        <button>Logout</button>
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft