Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm following This tutorial to implement my own ASP.NET authentication. At first I want to make this code able to run, then Debug to see how the flow is going, but I'm being stuck at the beginning, the principalService and context is always is null event I have regiser in Unityconfig.cs.

Global.asax
C#
public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            var principalService = DependencyResolver.Current.GetService<IPrincipalService>(); // always null
            var context = DependencyResolver.Current.GetService<HttpContextBase>(); // always null
            // Set the HttpContext's User to our IPrincipal
            context.User = principalService.GetCurrent();
        }
    }

UnityConfig.cs
C#
public static void RegisterTypes(IUnityContainer container)
        {
            container
               .RegisterType<IPrincipalService, MuchoSupportPrincipalService>();
        }


Thanks for reading.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900