The page requires session state that is no longer available..

When using MobileControls in .Net 2.0 it seems whenever a user's session times out and they do a post back they get the error:

The page requires session state that is no longer available. Either the session has expired, the client did not send a valid session cookie, or the session state history size is too small. Try increasing the history size or session expiry limit.

If I disable viewstate for the page this error won't happen but I get other errors when asp.net tries to re-bind the values of drop downs.

To reproduce this issue create Default.aspx with

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<mobile:Form ID="MainForm" Runat="server">
<mobile:SelectionList ID="EndPoint" SelectType="DropDown" Runat="server" BreakAfter="true">
<Item Text="Test1" Value="test1" />
<Item Text="Test2" Value="test2" />
mobile:SelectionList>
<mobile:Command ID="TestPost" Runat="server" OnClick="TestPost_Click" BreakAfter="True">TestPostmobile:Command>
mobile:Form>
body>
html>
  Default.aspx.cs with:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.MobileControls.MobilePage
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void TestPost_Click(object sender, EventArgs e)
{
}
}

 

and web.config with:

 





<configuration>

<appSettings />
<connectionStrings />

<system.web>


<compilation debug="false" />



<authentication mode="Windows" />



<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">

customErrors>



<httpRuntime useFullyQualifiedRedirectUrl="true" />



<mobileControls cookielessDataDictionaryType="System.Web.Mobile.CookielessData" />


<deviceFilters>
<filter name="isJPhone" compare="Type" argument="J-Phone" />
<filter name="isHTML32" compare="PreferredRenderingType" argument="html32" />
<filter name="isWML11" compare="PreferredRenderingType" argument="wml11" />
<filter name="isCHTML10" compare="PreferredRenderingType" argument="chtml10" />
<filter name="isGoAmerica" compare="Browser" argument="Go.Web" />
<filter name="isMME" compare="Browser" argument="Microsoft Mobile Explorer" />
<filter name="isMyPalm" compare="Browser" argument="MyPalm" />
<filter name="isPocketIE" compare="Browser" argument="Pocket IE" />
<filter name="isUP3x" compare="Type" argument="Phone.com 3.x Browser" />
<filter name="isUP4x" compare="Type" argument="Phone.com 4.x Browser" />
<filter name="isEricssonR380" compare="Type" argument="Ericsson R380" />
<filter name="isNokia7110" compare="Type" argument="Nokia 7110" />
<filter name="prefersGIF" compare="PreferredImageMIME" argument="image/gif" />
<filter name="prefersWBMP" compare="PreferredImageMIME" argument="image/vnd.wap.wbmp" />
<filter name="supportsColor" compare="IsColor" argument="true" />
<filter name="supportsCookies" compare="Cookies" argument="true" />
<filter name="supportsJavaScript" compare="Javascript" argument="true" />
<filter name="supportsVoiceCalls" compare="CanInitiateVoiceCall" argument="true" />
deviceFilters>

system.web>
configuration>

  

Then browse to Default.aspx, click the button, clear your cookies and session variables and click the button again and you'll get the error.  Any help would be appreciated.

0
crisco96 5/3/2008 5:15:34 PM
📁 asp.net.mobile_devices
📃 3052 articles.
⭐ 1 followers.

💬 7 Replies
👁️‍🗨️ 156 Views
This message means that session is expired but page tries to use it. This message is given by page's default viewstate expiring handler.

Add the following method to your page to solve this issue:


public void OnViewStateExpire(EventArgs e)
{
    HttpContext.Current.Session.Abandon();
    this.RedirectToMobilePage("mobile page url here", true);
}

Don't forget to mark solution providing post as "Answered".
It helps others to find correct solutions!

Also visit my ASP.NET blog!
0
DigiMortal 5/3/2008 9:30:26 PM

 Just a slight modification to the code and it works great:

 

protected override void OnViewStateExpire(EventArgs e)
{
	HttpContext.Current.Session.Abandon();
	RedirectToMobilePage("~/Default.aspx");
}
  
0
crisco96 5/5/2008 11:36:26 AM

Hello,

a quick workaround for this issue is to set the sessionStateHistorySize in the Web.config to a hight value:

<mobileControls cookielessDataDictionaryType="System.Web.Mobile.CookielessData" sessionStateHistorySize="100" />
The following blog post explains why this error occurs: Viewstate error in mobile ASP.NET app
 
ttklf4 on Twitter
0
SKT_01 5/20/2008 7:36:57 AM

Hi all,

I have a small problem, please see if any one can help me out.

I have a mobile website wherein i have used Object List and has binded it with values from database. ON selecting a particular record, the details are automatically displayed.

I tested it in .net emulators and worked fine BUT when i tested it in OpenWave simulator i am getting following error.

 The page requires session state that is no longer available. Either the session has expired, the client did not send a valid session cookie, or the session state history size is too small. Try increasing the history size or session expiry limit.

I am new in web development. Please help

~Satbir

0
satbirhundal 4/24/2009 6:12:10 AM

Hello,

you should not use obsolete software to develop mobile web applications.

The Openwave emulator is completely outdated and doesn't support cookies on localhost. That's the reason of your error. 

 


ttklf4 on Twitter
0
SKT_01 4/24/2009 6:23:52 AM

Ok, thanks.

Can you suggest some simulators which i can use beside .net emulators.

I want that the site should be supported by most of the browsers.

So, Object List works fine in most of the browsers?

~Satbir

0
satbirhundal 4/24/2009 6:32:21 AM

Hello,

one of the best emulators is the iPhone simulator from Apple Inc. which runs only on a Mac. The iphone is one of the most used devices for mobile internet.


ttklf4 on Twitter
0
SKT_01 4/24/2009 8:00:38 AM