NullReferenceException in FederatedAuthentication.GetHttpContextModule() when calling SecurityManager.AuthenticateUser
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 www.sitefinity.com/.../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
I'm still seeing this issue.
Has anyone confirmed whether this is fixed yet? Or if there is a workaround?
i was also waiting for the update!
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