.Net MVC Partial View会话到期时加载登录页面 [英] .Net MVC Partial View load login page when session expires

查看:389
本文介绍了.Net MVC Partial View会话到期时加载登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.net MVC 4构建web应用程序。

I am building a web application using .net MVC 4.

我有一个ajax表单来编辑数据。

I have ajax form to edit data.

>

如果用户闲置15分钟,它将使用户的会话过期。当这种情况发生,如果用户点击编辑按钮它加载登录页面的部分内容,因此现在的当前会话过期。

If the user is idle for 15 mins it will expire the session of the user. When that happens if user click edit button it loads the login page inside the partial content hence now the current session expires.

>

编辑链接 - cshtml代码

Edit Link - cshtml code

@Ajax.ActionLink("Edit", MVC.Admin.Material.ActionNames.TagEditorPanel, MVC.Admin.Material.Name, new { isView = "false", id = Model.ID.ToString() }, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "materialTagBox", InsertionMode = InsertionMode.Replace }, new { @class = "editlinks" })

[Authorize]
public virtual ActionResult TagEditorPanel(bool isView, int id)
{
   //do something
   return PartialView(MVC.Admin.Material.Views._tag, response);
}

Web.config

Web.config

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

我明白为什么会发生。我不知道如何解决它。我想阻止它,我想直接将用户重定向到登录页面。

I understand why it is happening. I don't know how to resolve it. I want to prevent it and I want to redirect user to login page directly. How can I achieve this?

推荐答案

如何实现这一点?

也许是一个黑客答案,但您可以将表单认证中的重定向位置更改为使用javascript将窗口位置设置为登录页面的页面。

Maybe a hacky answer, but you can change the redirect location in forms authentication to a page that sets the window location to the login page with javascript.

Web配置

<authentication mode="Forms">
  <forms loginUrl="~/Account/RedirectToLogin" timeout="2880" />
</authentication>

帐户管理员

public ActionResult RedirectToLogin()
{
    return PartialView("_RedirectToLogin");
}

_RedirectToLogin View

_RedirectToLogin View

<script>
    window.location = '@Url.Action("Login", "Account")';
</script>

这篇关于.Net MVC Partial View会话到期时加载登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆