问题描述
我正在尝试使用Identity和Owin登录用户,然后在会话结束后保持登录状态。用户数据存储在SQL Server中。当我在调试器中运行它时,它似乎正在工作。
问题是:,当我将其发布到远程站点时,我可以登录,但在大约5分钟后用户不再登录。我认为这是由于会话即将到期。正在使用我的startup.cs中设置的正确到期时间创建cookie。我正在使用授权部分来拒绝用户访问该网站。我以为我只需要使用登录方法进行更改,但似乎无法在线找到丢失的内容(主要是因为我并不真正知道要搜索的内容)。 / p>
这就是我登录用户的方式
protected void SignIn(object sender,EventArgs e)
{
var userStore = new UserStore<IdentityUser>();
var userManager = new UserManager<IdentityUser>(userStore);
var user = userManager.Find(uname.Text,pwd.Text);
if (user != null)
{
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
var userIdentity = userManager.CreateIdentity(user,DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = true,AllowRefresh = true },userIdentity);
Response.Redirect("~/Main.aspx");
}
else
{
errorlbl.Text = "Invalid username or password.";
}
}
我的startup.cs
public class Startup
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application,visit https://go.microsoft.com/fwlink/?LinkID=316888
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,ExpireTimeSpan = TimeSpan.FromDays(14),CookieName = "MyCookieName",LoginPath = new PathString("/Login.aspx/")
});
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)