Asp.net mvc 会话结束后如何从表单身份验证注销

Asp.net mvc 会话结束后如何从表单身份验证注销,asp.net-mvc,forms-authentication,session-timeout,sessionend,Asp.net Mvc,Forms Authentication,Session Timeout,Sessionend,我的MVC应用程序使用FormsAuthentication登录 [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Login(FiNext.Models.User user) { try { using (HttpClient httpClient = new HttpClient())

我的MVC应用程序使用FormsAuthentication登录

    [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");

            }
        }
现在的问题是,当我使用页面上的正常注销按钮注销时,页面将被注销

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult LogOff()
    {
        try
        {
            FormsAuthentication.SignOut();

            return RedirectToAction("Home", "User");
        }
        catch (Exception ex)
        {                
            throw ex;
        }
    }
现在我点击了这个应用程序的任何url(比如“”),它被重定向到登录页面,因为我们已经注销并重定向到主页。 这是所需的功能,工作正常

但问题是当出现会话超时并触发会话结束事件时。现在,当我点击此应用程序的任何url(比如“”)时,我能够获取数据(这不应该发生)

因此,如何在会话结束时从窗体身份验证注销。 我在Global.asax的session_end事件中尝试了以下内容:

    protected void Session_End(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Session.Clear();
        Session.Abandon();
    }

但它给出了“对象引用未设置为对象实例”的异常。

也许我遗漏了什么,但听起来像是授权问题,而不是会话问题

您的UserList操作是否以某种方式受到保护

[Authorize]
public ActionResult UserList()
{
    return View();
}

[Authorize]
public ActionResult UserList()
{
    return View();
}