這裏是我的登錄密碼,問題發生在用戶登錄後重定向到「檔案」身份2.0用戶都被重定向回登錄
protected void UserLogin_Click(object sender, EventArgs e)
{
if (IsValid)
{
var manager = new IdentityModels.UserManager();
IdentityModels.User user = manager.Find(Username.Text, Password.Text);
if (user != null)
{
if (isUserActive(user.PatientId)=="isNotActive")
{
lblError.Text =
"you are no longer active. Please contact your local clinic to find out why.";
return;
}
if (isUserActive(user.PatientId) == "clinicNotActive")
{
lblError.Text =
"Your clinic is no longer active. Please contact your local clinic to find out why.";
return;
}
IdentityModels.IdentityHelper.SignIn(manager, user, RememberMe.Checked);
if (manager.IsInRole(user.Id,"Administrator") || manager.IsInRole(user.Id,"Staff") || manager.IsInRole(user.Id,"Physician"))
{
Response.Redirect("Dashboard");
}
if (Request.QueryString["Profile"] != null)
{
IdentityModels.IdentityHelper.RedirectToReturnUrl(Request.QueryString["Profile"], Response);
}
else
{
Response.Redirect("Profile");
}
}
else
{
ModelState.AddModelError("", "Invalid username or password");
lblError.Text = "Invalid username or password";
}
}
}
這裏是個人資料頁面上網頁的加載代碼:
var manager = new IdentityModels.UserManager();
IdentityModels.User user = manager.FindById(HttpContext.Current.User.Identity.GetUserId());
if (user == null)
{
var ex = new Exception("patient was null, BUT TRIED SIGNING IN NOW" + UserAccess.GetUserId().ToString());
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
Response.Redirect("Login");
}
Elmah日誌顯示異常「患者爲空,但試圖簽名爲0」。
因此,如果我的用戶成功登錄,他們必須是因爲他們正在打開個人資料頁面,那麼爲什麼他們中的一些人會遇到此錯誤。爲什麼用戶爲空?
我只是無法弄清楚,爲什麼它會影響一些但不是全部。當我重新發佈網站時,所有用戶都可以登錄幾分鐘,有時幾個小時,然後重新開始。
您使用表單身份驗證或Windows身份驗證? – Claies 2015-02-11 21:12:06
@Claies我不確定,因爲它們都不在我的web.config中。 – prospector 2015-02-11 21:19:29
那麼你可能使用表單身份驗證。 'HttpContext.CurrentUser.Identity'派生自成功登錄後在客戶端設置的cookie,其中包含身份驗證票據。如果cookie不可用或已過期,則「Identity」將爲空。因此,我會檢查用戶是否禁用了Cookie。 – Claies 2015-02-11 21:24:54