Unity and MVC Preview 4 membership

Aug 23, 2008 at 12:27 PM

Is it possible to intergrate the Unity with MVC preview 4 membership function?

Now,  when I try to access the register function, following error occurred.

"The type MembershipProvider does not have an accessible constructor"

I have regsiter the Service as follows under the global.asax already. 

   .RegisterType<IFormsAuthentication, FormsAuthenticationWrapper>()
   .RegisterType<MembershipProvider, SqlMembershipProvider>();

However, following error occurred.

 However, it has the following error but I found that the provider is not null.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 196:                // Attempt to register the user
Line 197:                MembershipCreateStatus createStatus;
Line 198: MembershipUser newUser = Provider.CreateUser(username, password, email, null, null, true, null, out createStatus);Line 199:
Line 200:                if (newUser != null)

Source File: D:\Projects\AppleCommunity.DeeTools\AppleCommunity.DeeTools.Web\Controllers\AccountController.cs    Line: 198

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   System.Web.Security.SqlMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) +691
   AppleCommunity.DeeTool.Web.Controllers.AccountController.Register(String username, String email, String password, String confirmPassword) in D:\Projects\AppleCommunity.DeeTools\AppleCommunity.DeeTools.Web\Controllers\AccountController.cs:198

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +71
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +261
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(MethodInfo methodInfo, IDictionary`2 parameters) +575
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +123
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +351
   System.Web.Mvc.<>c__DisplayClasse.<InvokeActionMethodWithFilters>b__b() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(MethodInfo methodInfo, IDictionary`2 parameters, IList`1 filters) +461
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(String actionName, IDictionary`2 values) +669
   System.Web.Mvc.Controller.Execute(ControllerContext controllerContext) +294
   System.Web.Mvc.Controller.System.Web.Mvc.IController.Execute(ControllerContext controllerContext) +36
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +421
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +71
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +36
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


and I found that the Description under the base {System.Configuration.Provider.ProviderBase}  of the SqlMembership porvider  and the ApplicationName property under the Provider are null .

What I missed?

Regards
Alex