小编Bas*_*ouk的帖子

如何在Asp.Net Identity Framework中向AspNetUsers表添加字段?

我正在探索新的asp.net身份.使用代码优先和迁移功能向Users表"AspNetUsers"添加字段似乎很棒.

我想添加"Name","CreatedOn"和"CreatedFromIP"等列,并能够从.NET中读取它

有简单的解决方案吗?

asp.net-mvc-5 asp.net-identity-2

5
推荐指数
1
解决办法
1980
查看次数

如何自定义UseExternalSignInCookie?

我正在使用ASP.NET Identity 2.0并尝试将".AspNet.ExternalCookie"cookie的域设置为".mydomain.com",因为我想从另一个子域读取cookie.

一些解决方案说我可以更改此代码:

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
Run Code Online (Sandbox Code Playgroud)

对此:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
    CookieName = CookieAuthenticationDefaults.CookiePrefix + "External",
    LoginPath = new PathString("/Account/Login"),
    CookieDomain = ".mydomain.com"
});
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

在IAppBuilder属性中找不到SignInAsAuthenticationType的默认值.如果您的身份验证中间件以错误的顺序添加,或者如果缺少一个,则会发生这种情况.

我的完整代码如下所示:

        public void ConfigureAuth(IAppBuilder app)
    {
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);

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

        //app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
            CookieName = CookieAuthenticationDefaults.CookiePrefix + "External",
            LoginPath = new PathString("/Account/Login"),
            CookieDomain …
Run Code Online (Sandbox Code Playgroud)

asp.net owin asp.net-mvc-5 asp.net-identity-2

4
推荐指数
1
解决办法
6678
查看次数

标签 统计

asp.net-identity-2 ×2

asp.net-mvc-5 ×2

asp.net ×1

owin ×1