473,290 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,290 software developers and data experts.

How to allow a webbrowser to restart a session after it has expired?

Hi guys!

I have an issue that needs urgent resolution. Imagine this scenario:

You have:
1 production server running Windows Server 2003, IIS6 and an instance
of MSDE 2000.
There is an asp.net app (written in C#) running which has the only
purpose of rendering a page with a "Next" button on it and some status
info. When the user clicks the next button, an event is written to the
database and the status info is updated and returned. The page thus
reloads showing the new status info.

There are twenty remote workstations, each with a touch-screen and
running a custom application (written in Delphi 7.0), which has an
imbedded web browser on the main form. The web browser connects to the
ASP application and renders the page.

The reason the web browser is imbedded in another app is simply because
the application interface exposes other functionality which has been
developed before. The web browser is just an add-in. The additional
advantage is that the Delphi application can load a client-side config
file which identifies the station:

Each workstation has a unique integer ID (1 - 20), which gets added
onto the URL for the TWebBrowser's Navigate() method, for example:

var url : string;
..
..
url := '\\server\asp_app?stationid=' + IntToStr(stationID);
WebBrowser1.Navigate(url);

The asp.net app reads the station id from the request to start the
session, this ID is linked to each database record as described above.

My problem is that I need a way to pass along the station ID every time
the user clicks the next button in the browser. I can use the Session[]
keys to store the station ID, but the moment the session expires, this
information is lost. The stationID only gets passed along in the
initial Delphi app TWebBrowser page request, subsequent clicks on the
next button have nothing to do with the delphi app, the web browser
works in isolation.

Increasing the session timeout is not a solution, as a day or more may
go by between next button clicks. I need a way for the session to
expire naturally, but when the user clicks the next button, the session
is reopened (or a new one created, passing back the station id) without
having to rely on the delphi app to monitor what is happening to the
session.

Fundamentally, what is required is for the web page itself to remember
the station ID, and pass it back to the web server. So the web server
must somehow add the station info to the page, and when the button is
clicked, the page is resubmitted, and the web server app somehow reads
the remembered info.

How do I do this? I assume that the button itself will have to be
runat="client", with some imbedded Jscript to re-initialise the
request?

And the remembered station id? Do I need a hidden field to store it?
Any advice would be very much appreciated! Thank you in advance!

Regards,
Riaan

May 18 '06 #1
17 4934
Hi guys!

I have an issue that needs urgent resolution. Imagine this scenario:
You have:
1 production server running Windows Server 2003, IIS6 and an instance
of MSDE 2000.
There is an asp.net app (written in C#) running which has the only
purpose of rendering a page with a "Next" button on it and some status
info. When the user clicks the next button, an event is written to the
database and the status info is updated and returned. The page thus
reloads showing the new status info.
There are twenty remote workstations, each with a touch-screen and
running a custom application (written in Delphi 7.0), which has an
imbedded web browser on the main form. The web browser connects to the
ASP application and renders the page.
The reason the web browser is imbedded in another app is simply because

the application interface exposes other functionality which has been
developed before. The web browser is just an add-in. The additional
advantage is that the Delphi application can load a client-side config
file which identifies the station:
Each workstation has a unique integer ID (1 - 20), which gets added
onto the URL for the TWebBrowser's Navigate() method, for example:
var url : string;
..
..
url := 'http://server/asp_app?stationid=' + IntToStr(stationID);
WebBrowser1.Navigate(url);
The asp.net app reads the station id from the request to start the
session, this ID is linked to each database record as described above.
My problem is that I need a way to pass along the station ID every time

the user clicks the next button in the browser. I can use the Session[]

keys to store the station ID, but the moment the session expires, this
information is lost. The stationID only gets passed along in the
initial Delphi app TWebBrowser page request, subsequent clicks on the
next button have nothing to do with the delphi app, the web browser
works in isolation.
Increasing the session timeout is not a solution, as a day or more may
go by between next button clicks. I need a way for the session to
expire naturally, but when the user clicks the next button, the session

is reopened (or a new one created, passing back the station id) without

having to rely on the delphi app to monitor what is happening to the
session.
Fundamentally, what is required is for the web page itself to remember
the station ID, and pass it back to the web server. So the web server
must somehow add the station info to the page, and when the button is
clicked, the page is resubmitted, and the web server app somehow reads
the remembered info.
How do I do this? I assume that the button itself will have to be
runat="client", with some imbedded Jscript to re-initialise the
request?
And the remembered station id? Do I need a hidden field to store it?
Any advice would be very much appreciated! Thank you in advance!
Regards,
Riaan

May 18 '06 #2
Oh, and another thing, I must work in cookieless mode. so cookies
aren't a solution either.

May 18 '06 #3
How does the button currently send the form? Is it a submit button?

If the form is a server form (e.g. has runat="server"), the URL that the
form is posted to will be the same as the original URL, so it will have
the station id in the querystring.

Otherwise you can either put the id in the querystring of the URL in the
form, or put it in a hidden field in the form.
Riaan wrote:
Hi guys!

I have an issue that needs urgent resolution. Imagine this scenario:

You have:
1 production server running Windows Server 2003, IIS6 and an instance
of MSDE 2000.
There is an asp.net app (written in C#) running which has the only
purpose of rendering a page with a "Next" button on it and some status
info. When the user clicks the next button, an event is written to the
database and the status info is updated and returned. The page thus
reloads showing the new status info.

There are twenty remote workstations, each with a touch-screen and
running a custom application (written in Delphi 7.0), which has an
imbedded web browser on the main form. The web browser connects to the
ASP application and renders the page.

The reason the web browser is imbedded in another app is simply because
the application interface exposes other functionality which has been
developed before. The web browser is just an add-in. The additional
advantage is that the Delphi application can load a client-side config
file which identifies the station:

Each workstation has a unique integer ID (1 - 20), which gets added
onto the URL for the TWebBrowser's Navigate() method, for example:

var url : string;
.
.
url := '\\server\asp_app?stationid=' + IntToStr(stationID);
WebBrowser1.Navigate(url);

The asp.net app reads the station id from the request to start the
session, this ID is linked to each database record as described above.

My problem is that I need a way to pass along the station ID every time
the user clicks the next button in the browser. I can use the Session[]
keys to store the station ID, but the moment the session expires, this
information is lost. The stationID only gets passed along in the
initial Delphi app TWebBrowser page request, subsequent clicks on the
next button have nothing to do with the delphi app, the web browser
works in isolation.

Increasing the session timeout is not a solution, as a day or more may
go by between next button clicks. I need a way for the session to
expire naturally, but when the user clicks the next button, the session
is reopened (or a new one created, passing back the station id) without
having to rely on the delphi app to monitor what is happening to the
session.

Fundamentally, what is required is for the web page itself to remember
the station ID, and pass it back to the web server. So the web server
must somehow add the station info to the page, and when the button is
clicked, the page is resubmitted, and the web server app somehow reads
the remembered info.

How do I do this? I assume that the button itself will have to be
runat="client", with some imbedded Jscript to re-initialise the
request?

And the remembered station id? Do I need a hidden field to store it?
Any advice would be very much appreciated! Thank you in advance!

Regards,
Riaan

May 18 '06 #4
SOLVED!!!

Göran, you're a five-star guy! A genius!

I tested what you suggested by having my asp.net app write to a text
file every time a new session starts and ends. I had mistakenly
believed that my Response.Redirect("startpage.aspx") was throwing away
the original query string, but it doesn't. The viewstate of the web
form (yes, it's runat="server") not only maintains the session id, but
clicking the button resubmits using the original ?stationid=# added on.

I have no more worries! Yeehaaaaw! (for now :-p)

Thank you so very much! I have much to learn, and with folks like you
around, that will happen much faster.

Knowing that the query string is preserved, the session timeout becomes
irrelevant.

Thanks again!

Riaan

May 18 '06 #5
Hang on, I spoke too fast.

It works the first time the session expires. The second time it
expires, the query strings get discarded, and it stops working.
Whyyyyyyy?

:-/

My poor hairline!

May 18 '06 #6
Okay, I've figured out what is going on.

On my button click event, I was calling Response.Redirect() to refer
back to this same page.

What I forgot was that the action itself causes a postback. The
Response.Redirect() removes the query strings, BUT, the remote object
lifetime of the cached page on the server was around 5 minutes. The
viewstate was being cached and used for the new request, but eventually
it expires gets discarded, and the new requests do not have a viewstate
to get info from. So it's a brand new, raw request.

If you allow the form to postback by itself, then the viewstate saved
in the page HTML *ALWAYS* gets used.

This is cool, but it doesn't solve the problem of maintaining the state
between different pages. I'll have to use hidden form fields.

May 18 '06 #7
Why are you bothering with the session expiration at all? Just send the
value along from page to page.

If you do a Response.Redirect you have to include the value in the
querystring, or it will be lost.

Riaan wrote:
Hang on, I spoke too fast.

It works the first time the session expires. The second time it
expires, the query strings get discarded, and it stops working.
Whyyyyyyy?

:-/

My poor hairline!

May 18 '06 #8
"Why are you bothering with the session expiration at all?"

Well, session expiration means that I cannot rely on session state
(cookies or URI) to maintain values.
The expiration of the page viewstate cache means that I cannot rely on
that to maintain the query strings when using Response.Redirect. (I
would like to be able to jump to other pages if I need to, so I need a
solution that works regardless)

"Just send the value along from page to page."

How do I do this? Please pardon my ignorance, but I've only been
working with ASP.net for two days. :-o

Thanks,
Riaan

May 18 '06 #9
Riaan wrote:
"Why are you bothering with the session expiration at all?"

Well, session expiration means that I cannot rely on session state
(cookies or URI) to maintain values.
The expiration of the page viewstate cache
The viewstate is not a cache, it's simply values that are stored encoded
in a hidden field. If you don't do a postback there is no viewstate.
means that I cannot rely on
that to maintain the query strings when using Response.Redirect.
It's not the viewstate that maintains the querystring of the form. The
action property of the form is just set to the URL that was used to
request the page.
(I
would like to be able to jump to other pages if I need to, so I need a
solution that works regardless)
Then it depends on how you jump to that page. If you make a redirect,
put the value in querystring. If you post a form, put the value in a
hidden field.
"Just send the value along from page to page."

How do I do this?
Either as form data or in the querystring.
Please pardon my ignorance, but I've only been
working with ASP.net for two days. :-o


Ignorance is simply cured by learning (unless combined with stupidity). ;)

Noone knows everyting, so we are all ignorant in some fields. :)
May 18 '06 #10
re:
"Just send the value along from page to page." How do I do this?


Are you using ASP.NET 2.0 ?

If you are, and your problem is maintaining state between different pages,
it's quite simple to use cross-page posting and the PreviousPage property :

http://msdn2.microsoft.com/en-us/library/ms178139.aspx

If you're using ASP.NET 1.1 and you don't want to use Session state,
you can use a hidden field, as you already suggested to yourself.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espańol : http://asp.net.do/foros/
===================================
"Riaan" <rm***@mighty.co.za> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com... "Why are you bothering with the session expiration at all?"

Well, session expiration means that I cannot rely on session state
(cookies or URI) to maintain values.
The expiration of the page viewstate cache means that I cannot rely on
that to maintain the query strings when using Response.Redirect. (I
would like to be able to jump to other pages if I need to, so I need a
solution that works regardless)

"Just send the value along from page to page."

How do I do this? Please pardon my ignorance, but I've only been
working with ASP.net for two days. :-o

Thanks,
Riaan

May 18 '06 #11
I've been banging away at it for a couple of hours, and I've come up
with the following solution (using the page's ViewState) that seems to
work very well. I have no idea whether it's a winning hack or a kluge.
You decide :-D

// In Global.asax.cs:
public class Global : System.Web.HttpApplication
{
public static string STATION_ID = "StationID";
May 18 '06 #12
Damn, I'm goooood :-p.

Derived a class from UI.Page, overrode the Onload event, now no need to
init the page each time, just need to make sure each web form class
derives from TMyPage.

public class TMyPage : System.Web.UI.Page
{
// override the OnLoad event so we don't have to init the
// page everytime outselves.
protected override void OnLoad(System.EventArgs e)
{
PreserveState();
base.OnLoad(e);
}

protected void PreserveState()
{
if (Session[Global.STATION_ID] == null) // session expired?
{
if (ViewState[Global.STATION_ID] == null) // do we have a saved
view state?
Response.Redirect("InvalidRequest.aspx", true);
else
Session.Add(Global.STATION_ID,
int.Parse(ViewState[Global.STATION_ID].ToString()));
}
else //nope, grab it
ViewState.Add(Global.STATION_ID,
int.Parse(Session[Global.STATION_ID].ToString()));
}
}

May 18 '06 #13
My opinion is that you are making this much more complicated than it is.

Explicitly send the value from page to page, so that you have control
over what's happening, instead of trying to hold on to the value using
intricate pieces of code that run behind the scenes.

What you are doing now is to put the value in differnt places where it
might be available later, then later try to get the value from one of
the places where it still might be.

It's a bit like putting a pair of glasses on top of most tables and
desks and shelfs instead of putting them in your pocket, then when you
need a pair, fumble around on the nearby furniture... ;)

Riaan wrote:
Damn, I'm goooood :-p.

Derived a class from UI.Page, overrode the Onload event, now no need to
init the page each time, just need to make sure each web form class
derives from TMyPage.

public class TMyPage : System.Web.UI.Page
{
// override the OnLoad event so we don't have to init the
// page everytime outselves.
protected override void OnLoad(System.EventArgs e)
{
PreserveState();
base.OnLoad(e);
}

protected void PreserveState()
{
if (Session[Global.STATION_ID] == null) // session expired?
{
if (ViewState[Global.STATION_ID] == null) // do we have a saved
view state?
Response.Redirect("InvalidRequest.aspx", true);
else
Session.Add(Global.STATION_ID,
int.Parse(ViewState[Global.STATION_ID].ToString()));
}
else //nope, grab it
ViewState.Add(Global.STATION_ID,
int.Parse(Session[Global.STATION_ID].ToString()));
}
}

May 18 '06 #14
I honestly have no idea what you mean when you say "Explicitely send
the value from page to page". What exactly do you mean? Saying that
this is what I need to do does not tell me what I need to do, if that
makes sense.

So how DO I pass a value from one form to another? Obviously, there's
no session state, so the page has to remember what values I want to
keep. How do I do that? Using a hidden form field? Using the form's
Viewstate?

I'm using ASP.NET 1.1, and my understanding is that individual pages
have nothing to do with each other, they are unaware of each other and
what data is carried by them. The server app simply serves each request
in turn without giving a damn about page history. That is why state
management via Session vars or cookies or whatever are required, to
"bridge" the flow of data between forms. Because I cannot rely on those
features, I have to roll my own.

This is exactly what I'm doing with the form's viewstate. Each request
rebuilds the session state (if expired) from the data stored in the
viewstate, and session timeouts become irrelevant. Remember that the
viewstate is out of scope when the session starts, so I have to use the
Session variables to save values. The moment that the page viewstate
becomes available (OnLoad), I save the session vars to the viewstate.

May 19 '06 #15
Riaan wrote:
I honestly have no idea what you mean when you say "Explicitely send
the value from page to page". What exactly do you mean? Saying that
this is what I need to do does not tell me what I need to do, if that
makes sense.
What I mean is that you should send the value in each request in a way
so that you certainly know that you can pick it up in the next page.
So how DO I pass a value from one form to another? Obviously, there's
no session state, so the page has to remember what values I want to
keep. How do I do that? Using a hidden form field? Using the form's
Viewstate?
That depends on how you are requesting the page.

For a GET request (a link or a redirect) put the value in querystring.

For a POST request (posting a non-server form) put the value in a hidden
field or in the querystring.

For a postback put the value in viewstate, in a hidden field or in the
querystring.
I'm using ASP.NET 1.1, and my understanding is that individual pages
have nothing to do with each other, they are unaware of each other and
what data is carried by them. The server app simply serves each request
in turn without giving a damn about page history. That is why state
management via Session vars or cookies or whatever are required, to
"bridge" the flow of data between forms. Because I cannot rely on those
features, I have to roll my own.

This is exactly what I'm doing with the form's viewstate. Each request
rebuilds the session state (if expired) from the data stored in the
viewstate, and session timeouts become irrelevant. Remember that the
viewstate is out of scope when the session starts, so I have to use the
Session variables to save values. The moment that the page viewstate
becomes available (OnLoad), I save the session vars to the viewstate.


That method relies on either that the session has not expired or that
you are doing a postback. If you request a page any way that is not a
postback when the session has expired, it will fail.
May 19 '06 #16
Hmm. Some stuff to think about.

All my forms are web forms, and I only ever redirect in click events of
buttons or imagebuttons, using Response.Redirect(). It always works. It
hasn't failed on me yet. I've even set my session time-outs to 1
minute, left forms open overnight, and this morning they were still
working perfectly.

I am specifically not relying on postback, and it still works after the
session has expired...?

May 19 '06 #17
Riaan wrote:
Hmm. Some stuff to think about.

All my forms are web forms, and I only ever redirect in click events of
buttons or imagebuttons, using Response.Redirect(). It always works. It
hasn't failed on me yet. I've even set my session time-outs to 1
minute, left forms open overnight, and this morning they were still
working perfectly.
Yes, if you keep it that way the viewstate will work, as you use
postback for every request except redirects, and when you do redirects
the session won't time out in the short time between the redirect being
sent to the browser and the browser requests the new page.
I am specifically not relying on postback, and it still works after the
session has expired...?


Yes, you are. The viewstate is only available if you do a postback.
May 19 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David B | last post by:
Hi, Could somebody please tell me how I check whether a session is dead based soley on the Session.SessionID. At present the timeout is set to 20 minutes in IIS, I am aware that I can reset...
1
by: Vetrivel | last post by:
Application architecture : Develop interface between two existing systems, a. Enterprise CRM system b. Web based intranet system. Environment : Intranet Server : IIS and ASP. Script :...
6
by: Keith | last post by:
Is there any way of detecting whether a session variable does not exist because it expired or because it simply did not exist in the first place? Thanks
2
by: Chris Langston | last post by:
I have a Web Server running IIS 5 or 6 on Windows 2K and Windows 2003 Server that is experiencing strange shutdown problems. We are using ASP.NET v1.1 and our application is written in VB.NET ...
3
by: Simon | last post by:
Hi all, Any help with this would be much appreciated: I have a site where the session needs to timeout because of security concerns. I want to send the user back to the login page if the...
4
by: Nick | last post by:
Hi I am a little stuck. I have a web app which uses cookieless session management. I would like to inform a user when their session has ended but cannot work out how to implement. I thought...
6
by: NH | last post by:
How can I warn a user that their session has expired when they click on a button etc?
1
by: magix8 | last post by:
Hi, I have a portal with logon session coded in ASP. From the Portal Main screen, i access to a popup-window screen to do my activity. Whenever session expired, the popup-window screen will...
4
by: sriram | last post by:
Hello Friends, I am new to this group so big HIIIIIIII to all :) fine i have a serious doubt about session handling in PHP. After 20 min (default time) session getting expired, session values...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.