Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2007, 07:19 AM
Authorized User
 
Join Date: Aug 2006
Posts: 39
Thanks: 1
Thanked 0 Times in 0 Posts
Default Calling web page from Global.asax

Hi,
I have a Global.asax file in which a function calls a my_method at given time interval. In this method I want to open a web page, how can I do this?

My code is like this:

void Aplication_Start(object sender,EventArgs e)
{
  ....
  my_method();
}

public static void my_method()
{
  //Here I want to write code for calling web page.
}

Pls tell if any idea.
Thanks


 
Old August 26th, 2007, 01:48 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Where will this page be opened? Do you want every client that starts browsing your site to go to some start page?

Application start happens only once when the application starts. I.e. when the first user hits your application since the application or IIS has been re/started. You can use the Session_Start method to catch each user when they first hit your application. Of course, this then depends on users allowing cookies otherwise every single page hit will be seen by the server as a new session.

Within the methods you can use Response.Redirect to go to the desired page. Again, though, if your user doesn't support cookies then they will go into an infinite loop because every page hit will be a new session which will redirect them forever.

What are you looking to achieve with this? Perhaps there is a better way.

-Peter
 
Old August 27th, 2007, 05:58 AM
Authorized User
 
Join Date: Aug 2006
Posts: 39
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for reply,
Actually I want to show a popup window to the logged in user at a specified interval of time. In Aplication_Start there is a counter loop which checkes for the time. As the scheduled time is reached, it calls my_method() which then should popup a window.

I tried writing in my_method:

HttpContext Context=(HttpContext)Sender;
Context.Response.Redirect and Context.Server.Transfer
work fine in Aplication_Start but not in my_method.

Is there any other way for this?
Thanks
 
Old August 27th, 2007, 08:25 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm getting the impression that you don't understand the statelessness of a web application.

Application_Start ONLY runs ONCE when the first client hits the site after the application has been unloaded (server reboot, IIS restart, etc).

Session_Start runs on the first hit for a new client.

Those methods are not user specific. This article might help you get a better understanding of Global.asax:
http://aspalliance.com/articleViewer.aspx?aId=440&pId=

From your posts it sounds like you want to affect the user's experience at some point in time after they have entered the site. This would typically require some kind of session value storage (asp session, a cookie) to track the user's time.

If you want to have a window pop up at the designated time you need to use javascript so it happens on the client end. You can't trigger a client event from the server after the client has received a page.

You should probably write some javascript that gets written to the all your site pages. You can use the client side "setTimeout" method to set an event that will happen after the predetermined wait time. The trick will be that you'll need to save the site entry time (session or cookie) and recalculate the wait time on each page hit. That way as the user moves around your pages they'll always have the popup primed to fire at the right time based on the time calculation.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to declare the global variable in global.asax? calyn_gately ASP.NET 3.5 Basics 0 August 6th, 2008 08:06 PM
Remote-obj under IIS and Web.Config + Global.asax lok_tan .NET Framework 2.0 1 March 17th, 2008 01:21 AM
an error in Global.asax when the page is started lovehorse BOOK: ASP.NET Website Programming Problem-Design-Solution 5 October 17th, 2006 07:22 PM
what is global.asax? gaurav_jain2403 General .NET 1 February 3rd, 2006 02:40 PM
Session States, Global. asax and web.config ohmbhu General .NET 2 July 1st, 2004 09:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.