我的MVC应用程序使用FormsAuthentication登录后signout。如何从形式认证会话结束
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(FiNext.Models.User user)
{
try
{
using (HttpClient httpClient = new HttpClient())
{
var task = httpClient.PostAsJsonAsync<FiNext.Models.User>(String.Concat(ServiceUri.ApiUrl,"/Test/Validate"), user).Result;
FormsAuthentication.SetAuthCookie(user.Name, false);
SessionHelpers.UserId = user.Id;
return RedirectToAction("Create");
}
}
而且它有一个会话超时一分钟(在web.config中)的,一旦会话超时被调用时,我正在清除Global.asax中session_end事件中的会话。
protected void Session_End(object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
}
现在,当我退出在页面上使用正常的注销按钮的问题,该页面被注销。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
try
{
FormsAuthentication.SignOut();
return RedirectToAction("Home", "User");
}
catch (Exception ex)
{
throw ex;
}
}
,现在我打这个应用程序的任何URL(说“http://abcd.com/User/UserList”)被重定向到登录页面,因为我们已经注销并重定向到主页。 这是所需的功能和正常工作。
但问题是当会话超时和session_end事件被触发。现在当我打这个应用程序的任何网址(说“http://abcd.com/User/UserList”),我能够获得数据(这不应该发生)。
那么如何在session_end被触发时从表单身份验证中注销。 我在Global.asax中尝试这种在Session_End中的事件:
protected void Session_End(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Session.Clear();
Session.Abandon();
}
但其赋予“对象引用不设置到对象的实例。”例外。