Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# OWIN/Identity 2.0-将pk从字符串更改为GUID_C#_Asp.net_Asp.net Mvc_Asp.net Identity - Fatal编程技术网

C# OWIN/Identity 2.0-将pk从字符串更改为GUID

C# OWIN/Identity 2.0-将pk从字符串更改为GUID,c#,asp.net,asp.net-mvc,asp.net-identity,C#,Asp.net,Asp.net Mvc,Asp.net Identity,我正在尝试将asp.net identity的pk系统从数据库nvarchar(128)->uniqueidentifier更改为字符串->Guid中的代码。基于将pk更改为int32,我只有一个问题似乎无法解决 在我的Startup.Auth.cs课程中,我更改了以下内容 app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAu

我正在尝试将asp.net identity的pk系统从数据库nvarchar(128)->uniqueidentifier更改为字符串->Guid中的代码。基于将pk更改为int32,我只有一个问题似乎无法解决

在我的
Startup.Auth.cs
课程中,我更改了以下内容

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {   //error on the line below
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, Guid>(TimeSpan.FromMinutes(20), (manager, user) => user.GenerateUserIdentityAsync(manager), (identity) => Guid.Parse(identity.GetUserId()))
            }
        });  
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Account/Login”),
Provider=新CookieAuthenticationProvider
{//下面一行有错误
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity(TimeSpan.FromMinutes(20),(manager,user)=>user.GenerateUserIdentityAsync(manager),(identity)=>Guid.Parse(identity.GetUserId())
}
});  
我犯了两个我无法理解的错误。身份的结构让我对这么多的泛型感到非常困惑。我知道它说它收到了错误的参数类型,但我不知道如何解决这个问题

错误

错误1与的最佳重载方法匹配 'Microsoft.AspNet.Identity.Owin.SecurityStampValidator.OnValidateIdentity(System.TimeSpan, System.Func>, System.Func)“”具有 一些无效的参数

错误2参数2:无法从“lambda表达式”转换为 'System.Func>'

有人能提供一些见解吗?

app.UseCookieAuthentication(新的CookieAuthenticationOptions
  app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/_layouts/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, WebUser,Guid>(
                    validateInterval: TimeSpan.FromMinutes(30),
                     regenerateIdentityCallback: (manager, user) => 
                    user.GenerateUserIdentityAsync(manager), 
                getUserIdCallback:(id)=>(Guid.Parse(id.GetUserId())))

            }
        });        
{ AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie, LoginPath=新路径字符串(“/\u布局/帐户/登录”), Provider=新CookieAuthenticationProvider { //允许应用程序在用户登录时验证安全戳。 //这是一种安全功能,在您更改密码或向帐户添加外部登录时使用。 OnValidateIdentity=SecurityStampValidator.OnValidateIdentity( validateInterval:TimeSpan.FromMinutes(30), regenerateIdentityCallback:(管理者,用户)=> user.GenerateUserIdentityAsync(管理器), getUserIdCallback:(id)=>(Guid.Parse(id.GetUserId())) } });
也许它会对您有所帮助:请参阅此处的IdentityModels、IdentityConfig和Startup.Auth文件以了解如何实现它:这是大量带有说明的代码。描述代码回答问题的原因总是一个好主意。请回答添加说明。如果我使用此方法,注册后会出现异常“UserId not found.”。由GenerateUserIdentityAsync->manager.CreateIdentityAsync引发(这是DefaultAuthenticationTypes.ApplicationOkie);有什么建议吗?