- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 ASP.NET Identity 2.0 并尝试将“.AspNet.ExternalCookie”cookie 的域设置为“.mydomain.com”,因为我想从另一个子域读取 cookie。
一些解决方案说我可以更改此代码:
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
CookieName = CookieAuthenticationDefaults.CookiePrefix + "External",
LoginPath = new PathString("/Account/Login"),
CookieDomain = ".mydomain.com"
});
A default value for SignInAsAuthenticationType was not found in IAppBuilder Properties. This can happen if your authentication middleware are added in the wrong order, or if one is missing.
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 = ".mydomain.com",
ExpireTimeSpan = TimeSpan.FromMinutes(5)
});
app.UseMicrosoftAccountAuthentication(
clientId: "1",
clientSecret: "1");
app.UseTwitterAuthentication(
consumerKey: "2",
consumerSecret: "2");
app.UseFacebookAuthentication(
appId: "3",
appSecret: "3");
app.UseGoogleAuthentication();
}
最佳答案
似乎有两种解决方案:
解决方案1:
添加
using Microsoft.Owin.Security;
app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ExternalCookie);
app.Properties["Microsoft.Owin.Security.Constants.DefaultSignInAsAuthenticationType"] = "ExternalCookie";
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive
如果用户从外部提供者进行身份验证,则应该添加它以便不会自动登录用户(它应该由应用程序控制,他应该只通过 ApplicationCookie 进行身份验证)。
app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ExternalCookie);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive,
LoginPath = new PathString("/accounts/signin"),
CookieHttpOnly = true,
CookieName = CookieAuthenticationDefaults.CookiePrefix + "External",
CookieDomain = ".mydomain.com"
});
关于asp.net - 如何自定义 UseExternalSignInCookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23733325/
我正在使用 ASP.NET Identity 2.0 并尝试将“.AspNet.ExternalCookie”cookie 的域设置为“.mydomain.com”,因为我想从另一个子域读取 cook
我使用 Owin 通过 Google oAuth 进行授权。以下是我的 cookie 的配置方式: // Enable the application to use a cookie to store
我有两个 VS 2013 MVC 5 SPA web 项目。两者都是新创建的并且没有被修改(即仍然是 vanilla 模板)。其中一种有效,一种无效。我能看到的唯一区别是,一个是在从 VS 2010
我是一名优秀的程序员,十分优秀!