gpt4 book ai didi

c# - 应用程序停止生成登录 cookie

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:31 28 4
gpt4 key购买 nike

我一直在寻找这个问题的答案,但这个问题似乎很复杂,我正在努力寻找答案。

我是一名新手软件开发人员,在一家初创公司工作,刚刚完成了供多个用户使用的第一个版本系统。本地测试软件没有问题,但是自从将软件发布到iis上的windows 2012服务器后,我发现登录系统存在重大问题。

当最初上传程序时,多个用户可以毫无问题地登录和使用该程序,但是(似乎)随机地,登录系统在当前已注销的所有计算机上完全停止运行。登录的人可以注销并使用他们的帐户或任何其他帐户重新登录,但此时已注销的人将完全失去对系统的访问权限。

在 Chrome 上使用开发人员工具时,所有这些计算机似乎都完全停止生成登录时创建的 cookie,只是重定向回登录屏幕。

系统仍然会识别错误的登录,并且每次我上传程序时都会在不同的计算机上发生这种情况。

我明白这是一个非常模糊的问题,但我正在努力解决这个问题!

正如我所说的,我是初学者,对在企业服务器上托管完全陌生,并且在身份或登录系统方面一般没有太多经验,因此非常感谢任何帮助。

我主要想知道问题最有可能是 iis,如果是的话,我应该在 iis 中查找什么?还是服务器安全设置?

当它在服务器上运行时,是否有一个有效的理由来调试它?

如果问题听起来像是身份文件已被编辑的编码问题,请告诉我它可能是哪个类,我会发布代码。

谢谢!

编辑:

全局.asax.cs

public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
WebApiConfig.Register(GlobalConfiguration.Configuration);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);

//Creates roles and adds an admin on first start
RoleCreator rc = new RoleCreator();
rc.CreateRoles();
rc.AddAdmin();
}
}

启动.Auth.cs

public partial class Startup {

public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(UnitContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieName="TrackerCookie",
LoginPath = new PathString("/Login/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

// Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
}

最佳答案

问题现已解决。

对于遇到相同问题的任何人,该问题是由名为“katana bug #197”的错误引起的。

最简单的修复方法是下载“kentor.OwinCookieSaver”NuGet 包。并在启动时将 app.UseKentorOwinCookieSaver(); 添加到您的应用程序 cookie 配置之上。

https://github.com/KentorIT/owin-cookie-saver

 // kentor.OwinCookieSaver for 'katana bug #197' (login cookies being destroyed on logout!)
app.UseKentorOwinCookieSaver();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieName="LoginCookie",
LoginPath = new PathString("/Login/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});

Microsoft 已意识到该问题并将在 2015 年解决。

关于c# - 应用程序停止生成登录 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31720820/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com