+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / NullReferenceException in FederatedAuthentication.GetHttpContextModule() when calling SecurityManager.AuthenticateUser

NullReferenceException in FederatedAuthentication.GetHttpContextModule() when calling SecurityManager.AuthenticateUser

4 posts, 0 answered
  1. Bo Chulindra
    Bo Chulindra avatar
    35 posts
    Registered:
    17 Dec 2013
    26 Jun 2014
    Link to this post

    I thought I'd post this because it may be useful to others.

     

    I created a custom MVC login widget. Inside my controller, I make the following call:

    var userLoggingReason = SecurityManager.AuthenticateUser(userManager.Provider.Name, username, password, false);

    This call fails with a NullReferenceException (stack trace below). After some investigating, it turns out that the NullReferenceException is because HttpContext.Current.ApplicationInstance is null.

     I found the following in http://www.sitefinity.com/developer-network/forums/general-discussions-/internal-hotfix-builds which I think will fix the problem, but I haven't upgraded to verify:

     

    Sitefinity 7.0.5110 Version Notes
    MVC context does not copy ApplicationInstance and Cookies

     

    Stack Trace: 

    [NullReferenceException: Object reference not set to an instance of an object.]
    Microsoft.IdentityModel.Web.FederatedAuthentication.GetHttpContextModule() +83
    Microsoft.IdentityModel.Web.FederatedAuthentication.GetHttpModule() +200
    Microsoft.IdentityModel.Web.FederatedAuthentication.get_SessionAuthenticationModule() +33
    Telerik.Sitefinity.Security.Claims.SitefinityClaimsAuthenticationModule.AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, Boolean persistent) +177
    Telerik.Sitefinity.Security.SecurityManager.AuthenticateUser(User user, UserManager manager, Boolean persistent) +515
    Telerik.Sitefinity.Security.SecurityManager.AuthenticateUser(String membershipProviderName, String userName, String password, Boolean persistent, User& user) +279
    Telerik.Sitefinity.Security.SecurityManager.AuthenticateUser(String membershipProviderName, String userName, String password, Boolean persistent) +57
    SitefinityWebApp.Mvc.Controllers.LoginController.Login(String username, String password) in c:\Users\Bo\Plastic Workspaces\<deleted>\Mvc\Controllers\LoginController.cs:77
    SitefinityWebApp.Mvc.Controllers.LoginController.Index(LoginViewModel loginViewModel) in c:\Users\Bo\Plastic Workspaces\<deleted>\Mvc\Controllers\LoginController.cs:62
    lambda_method(Closure , ControllerBase , Object[] ) +159
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
    System.Web.Mvc.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10() +55
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
    System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +21
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
    Telerik.Sitefinity.Mvc.ControllerWrapper.Execute() +148

  2. Bo Chulindra
    Bo Chulindra avatar
    35 posts
    Registered:
    17 Dec 2013
    22 Sep 2015
    Link to this post

    I'm still seeing this issue.

     Has anyone confirmed whether this is fixed yet? Or if there is a workaround?

  3. Balaji
    Balaji avatar
    4 posts
    Registered:
    15 Jun 2015
    09 Mar
    Link to this post
    i was also waiting for the update!
  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    14 Mar
    Link to this post
    Hello Bo,

    Testing the scenario to get the ApplicationInstance - user identity on Sitefinity 8.2 in controller seems working fine (screenshot).

    Can you please provide more information about the code used and the scenario you want to achieve?

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered