ASP.NET会话不会再让存储跨页 [英] ASP.NET Session is not keeping stored across pages

查看:108
本文介绍了ASP.NET会话不会再让存储跨页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我创建了一个加了键值对的会话,并确认该网页上的会议认为,对一个登录页面。 接下来,我试图去到另一个页面,查找该对的会话,它不存在。我已经把超时的会话15000,所以它不会超时。 我目前使用静态类来看看会议,HttpContext.Current.Session。 每个页面调用这个静态类后,我看会议,但每次会话密钥数= 0,除了对登录页上。

 公共静态类UserAuthenticationManager
{
    公共静态布尔IsAuthenticated()
    {
        UserAuthenticationTicket票=((UserAuthenticationTicket)HttpContext.Current.Session [DefinesPL.UserTicketSessionName]);

        字符串的redirectUrl =的String.Format(DefinesPL.LoginPage);

        如果(门票!= NULL)
        {
            如果(ticket.IsExpired())
            {
                HttpContext.Current.Session.Abandon();
                HttpContext.Current.Response.Redirect(的redirectUrl,真正的);
            }
        }
        其他
        {
            HttpContext.Current.Session.Abandon();
            HttpContext.Current.Response.Redirect(的redirectUrl,真正的);
        }

        返回true;
    }
 

解决方案

可能还需要确保你有Global.asax中添加到您的项目。我相信我遇到了这个之前,在一个新的会话是为每个HTTP请求创建的。

First, I created a Login page that added a key value pair to the session and verified that on that page the session holds that pair. Next, I attempt to go to another page that looks for that pair in the session and it is not there. I've put the timeout for the session to 15000 so it won't timeout. I currently use a static class to look at the session, HttpContext.Current.Session. Each Page calls this static class to look at the session but every time the session key count = 0 except after I the pair on the login page.

public static class UserAuthenticationManager
{
    public static bool IsAuthenticated()
    {
        UserAuthenticationTicket ticket = ((UserAuthenticationTicket)HttpContext.Current.Session[DefinesPL.UserTicketSessionName]);

        string redirectUrl = String.Format(DefinesPL.LoginPage);

        if (ticket != null)
        {
            if (ticket.IsExpired())
            {
                HttpContext.Current.Session.Abandon();
                HttpContext.Current.Response.Redirect(redirectUrl, true);
            }
        }
        else
        {
            HttpContext.Current.Session.Abandon();
            HttpContext.Current.Response.Redirect(redirectUrl, true);
        }

        return true;
    }

解决方案

Might also want to make sure you have Global.asax added to your project. I believe i ran into this before, where a new session was created for every HTTP request.

这篇关于ASP.NET会话不会再让存储跨页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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