ASP.NET MVC 3.0 会话变量过期时重定向?

发布于 2024-12-14 05:58:39 字数 263 浏览 6 评论 0原文

在我的 ASP.Net MVC 3.0 应用程序中, 我正在整个应用程序中访问我的会话变量。 代码

HttpContext.Session["CustomerID"]= customerID;

当任何会话变量由于会话超时而不可用或为空时,我想将用户重定向到登录页面。

我该怎么办呢。 因为我在整个应用程序中使用会话变量,所以我无法在每个实例中检查变量是否为 null。

任何帮助将不胜感激。

谢谢

In my ASP.Net MVC 3.0 Application,
I am accessing my Session variable allover the application.
code

HttpContext.Session["CustomerID"]= customerID;

When any of the session variable is not available or null due to session time out, i would like to redirect the user to the login page.

How can i do it.
because i am using Session variable allover the application i can't check the variables for null at each instance.

Any help would be greatly appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里人 2024-12-21 05:58:39

我假设您希望会话到期后立即发生这种情况。为此,您需要某种类型的客户端代码 (javascript) 在某个设定的时间间隔内与服务器进行检查。

创建一个名为 IsServerExpired 的操作,并让它返回一个包含布尔值和重定向 url 的 json 对象。

编写一个 JavaScript 函数,用于向服务器进行检查,然后在返回的值为 true 时在 JavaScript 中执行重定向。

I assume you want this to happen as soon as the session expires. To do this, you need some type of client side code (javascript) checking back with the server on some set time interval.

Create an action called IsServerExpired and have it return a json object containing a boolean value, and the redirect url.

Write a javascript function that checks back with the server and then do the redirect in javascript when the value returned is true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文