Microsoft.AspNet.Identity.Owin.dll中发生System.ArgumentNullException

时间:2015-10-01 07:07:31

标签: c# asp.net asp.net-mvc

我正在尝试开发一个ASP MVC应用程序并试图创建一个简单的身份验证,它总是在我的计算机上创建一个新项目时起作用。 现在,我有一个在另一台机器上创建的解决方案,它在我的计算机上运行时抛出异常。

以下是抛出异常的代码

public IdentitySignInManager(BusinessModuleList modules, IAuthenticationManager authenticationManager)
        : base(modules.Get<IdentityUserManager<TUser, TDataAccessModule, TDataContext>>(), authenticationManager)
    {
        Prerequisites = new List<Prerequisite>();
        Modules = modules;
    }

上述方法位于IdentitySignInManager.cs文件中,如下所示

 public class IdentitySignInManager<TUser, TDataAccessModule, TDataContext> : SignInManager<TUser, String>, IBusinessModule
    where TUser: UserBase
    where TDataAccessModule : IdentityDataAccessModule<TUser, TDataContext>
    where TDataContext : IdentityDataContext<TUser>
{

    #region Properties

    /// <summary>
    /// The module list.
    /// </summary>
    public BusinessModuleList Modules { get; private set; }

    /// <summary>
    /// The prerequisites of the normal functionality of the module.
    /// </summary>
    public List<Prerequisite> Prerequisites { get; private set; }

    #endregion

    #region Constructors

    /// <summary>
    /// Initializes the new instance of IdentitySignInManager.
    /// </summary>
    /// <param name="modules">The module list.</param>
    /// <param name="authenticationManager">The authentication manager.</param>
    public IdentitySignInManager(BusinessModuleList modules, IAuthenticationManager authenticationManager)
        : base(modules.Get<IdentityUserManager<TUser, TDataAccessModule, TDataContext>>(), authenticationManager)
    {
        Prerequisites = new List<Prerequisite>();
        Modules = modules;
    }

    /// <summary>
    /// Initializes the new instance of IdentitySignInManager. Supressed.
    /// </summary>
    private IdentitySignInManager(UserManager<TUser, String> userManager, IAuthenticationManager authenticationManager)
        : base(userManager, authenticationManager)
    {
    }

    #endregion

    #region Methods

    /// <summary>
    /// Creates the claims based identity from the user.
    /// </summary>
    /// <param name="user">The user.</param>
    /// <param name="authenticationType">The authentication type. Ther default is "ApplicationCookie".</param>
    /// <returns>The claims based identity.</returns>
    public async Task<ClaimsIdentity> CreateUserIdentityAsync(TUser user, String authenticationType = DefaultAuthenticationTypes.ApplicationCookie)
    {
        return await Modules.Get<IdentityUserManager<TUser, TDataAccessModule, TDataContext>>().CreateIdentityAsync(user, authenticationType);
    }

    /// <summary>
    /// If disposing, calls dispose on the Context. Always nulls out the Context. Also disposes the Modules.
    /// </summary>
    /// <param name="disposing">True to dispose managed resources, false to not to dispose them.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            Modules.Dispose();
            Modules = null;
        }
        base.Dispose(disposing);
    }

    #endregion

}

它抛出的异常是以下

类型例外:

  

&#39; System.ArgumentNullException&#39;发生在   Microsoft.AspNet.Identity.Owin.dll但未在用户代码中处理

如果我点击F5并继续使用代码,它会在浏览器上显示此错误

值不能为空。 参数名称:userManager

Microsoft.AspNet.Identity.Owin.SignInManager 2..ctor(UserManager 2 userManager,IAuthenticationManager authenticationManager)    在Core.BusinessModules.Users.Modules.IdentitySignInManager 3..ctor(BusinessModuleList modules, IAuthenticationManager authenticationManager) in d:\projects\payroll\Trunk\Sources\Core.BusinessModules.Users\Modules\IdentitySignInManager.cs:line 50 at PR.Web.Application.Common.Modules.AppSignInManager..ctor(BusinessModuleList modules, IAuthenticationManager authenticationManager) in d:\projects\payroll\Trunk\Sources\PR.Web.Application\Common\Modules\AppSignInManager.cs:line 30 at PR.Web.Application.Common.Web.OWinContextCallbacks.CreateBusinessModules(IdentityFactoryOptions 1个选项,IOwinContext上下文)在d:\ projects \ payroll \ Trunk \ Sources \ PR.Web.Application \ Common \ Web \ OWinContextCallbacks.cs:第37行    在Microsoft.AspNet.Identity.Owin.IdentityFactoryProvider 1.Create(IdentityFactoryOptions 1个选项,IOwinContext上下文)    在Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.d__0.MoveNext()

在startup.cs上我有以下代码,其中

 private static void ConfigureAuthentication(IAppBuilder appBuilder)
    {

        appBuilder.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<AppUserManager, User>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie))
            }
        });

        appBuilder.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

    }

在完成上述代码后立即抛出异常。

我该如何修复此错误?

0 个答案:

没有答案