ASP.NET会话不会再让存储跨页再让、ASP、NET

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

首先,我创建了一个加了键值对的会话,并确认该网页上的会议认为,对一个登录页面。 接下来,我试图去到另一个页面,查找该对的会话,它不存在。我已经把超时的会话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;
    }
asp中,定义了一个label 用来显示从另一个页面获取过来的值,为什么显示不完整

解决方案

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.

阅读全文

相关推荐

最新文章