[Mono-list] Newbie Question: Web app life cycle events
Hi I'm new to mono and C#, I'm coming from a Java background. I've built my first test web-app using monodevelop using a tutorial I found on the web. (Code attached below). Everything works as expected. I then tried playing around with the Global.asax.cs by inserting Console.WriteLine() into each of the calls to try and get a feel for the life_cycle events and when they're called. Now when I run my application I get one call to Application_Start() - which I would've expected, but I get multiple calls to Application_BeginRequest, Session_Start() and Application_EndRequest() - which I would not have expected. Why do I get three calls? Regards Default.aspx %@ Page Language=C# Inherits=MyWebProject.Default % !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd; html head titleDefault/title /head body form id=form1 runat=server asp:button id=clickMeButton runat=server text=Click Me onClick=clickMeButton_Click/ asp:label id=outputLabel runat=server/ /form /body /html Default.aspx.cs using System; using System.Web; using System.Web.UI; namespace MyWebProject { public partial class Default : System.Web.UI.Page { public void clickMeButton_Click(object sender, EventArgs e) { object val = ViewState[ButtonClickCount]; int i = (val == null)? 1 : (int)val + 1; outputLabel.Text = string.Format (You clicked me {0} {1}, i, i==1?time:times); ViewState[ButtonClickCount] = i; } } } Global.asax.cs using System; using System.Collections; using System.ComponentModel; using System.Web; using System.Web.SessionState; namespace MyWebProject { public class Global : System.Web.HttpApplication { protected virtual void Application_Start(object sender, EventArgs e) { Console.WriteLine(Application_Start is called); } protected virtual void Session_Start(object sender, EventArgs e) { Console.WriteLine(Session_Start is called); } protected virtual void Application_BeginRequest(object sender, EventArgs e) { Console.WriteLine(Application_BeginRequest is called); } protected virtual void Application_EndRequest(object sender, EventArgs e) { Console.WriteLine(Application_EndRequest is called); } protected virtual void Application_AuthenticateRequest(object sender, EventArgs e) { } protected virtual void Application_Error(object sender, EventArgs e) { } protected virtual void Session_End(object sender, EventArgs e) { Console.WriteLine(Session_End is called); } protected virtual void Application_End(object sender, EventArgs e) { Console.WriteLine(Application_End is called); } } } ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] Newbie Question: Web app life cycle events
One possible cause to keep in mind is if Mono is handling all requests for the app them begin request etc will be called also for css files and images and javscript, not just .aspx This is similar to running in the Visual Studio web server. Running in IIS on windows, requests for css files and images will be handled by IIS and not by .NET. It is possible to configure things so that apache handles requests for css and images, but using xsp2 directly its going to handle all files. You may be able to find out what the request is for in those events with HttpContext.Current.Request.RawUrl Hope it helps, Joe On Mon, Oct 27, 2008 at 6:05 AM, Roger [EMAIL PROTECTED] wrote: Hi I'm new to mono and C#, I'm coming from a Java background. I've built my first test web-app using monodevelop using a tutorial I found on the web. (Code attached below). Everything works as expected. I then tried playing around with the Global.asax.cs by inserting Console.WriteLine() into each of the calls to try and get a feel for the life_cycle events and when they're called. Now when I run my application I get one call to Application_Start() - which I would've expected, but I get multiple calls to Application_BeginRequest, Session_Start() and Application_EndRequest() - which I would not have expected. Why do I get three calls? Regards Default.aspx %@ Page Language=C# Inherits=MyWebProject.Default % !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd; html head titleDefault/title /head body form id=form1 runat=server asp:button id=clickMeButton runat=server text=Click Me onClick=clickMeButton_Click/ asp:label id=outputLabel runat=server/ /form /body /html Default.aspx.cs using System; using System.Web; using System.Web.UI; namespace MyWebProject { public partial class Default : System.Web.UI.Page { public void clickMeButton_Click(object sender, EventArgs e) { object val = ViewState[ButtonClickCount]; int i = (val == null)? 1 : (int)val + 1; outputLabel.Text = string.Format (You clicked me {0} {1}, i, i==1?time:times); ViewState[ButtonClickCount] = i; } } } Global.asax.cs using System; using System.Collections; using System.ComponentModel; using System.Web; using System.Web.SessionState; namespace MyWebProject { public class Global : System.Web.HttpApplication { protected virtual void Application_Start(object sender, EventArgs e) { Console.WriteLine(Application_Start is called); } protected virtual void Session_Start(object sender, EventArgs e) { Console.WriteLine(Session_Start is called); } protected virtual void Application_BeginRequest(object sender, EventArgs e) { Console.WriteLine(Application_BeginRequest is called); } protected virtual void Application_EndRequest(object sender, EventArgs e) { Console.WriteLine(Application_EndRequest is called); } protected virtual void Application_AuthenticateRequest(object sender, EventArgs e) { } protected virtual void Application_Error(object sender, EventArgs e) { } protected virtual void Session_End(object sender, EventArgs e) { Console.WriteLine(Session_End is called); } protected virtual void Application_End(object sender, EventArgs e) { Console.WriteLine(Application_End is called); } } } ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list -- Joe Audette Software Solutions Architect Source Tree Solutions, LLC PO Box 621861 Charlotte, NC 28262 704.323.8225 [EMAIL PROTECTED] http://www.sourcetreesolutions.com http://www.mojoportal.com ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] Newbie Question: Web app life cycle events
On Monday 27 October 2008 12:12:21 Joe Audette wrote: One possible cause to keep in mind is if Mono is handling all requests for the app them begin request etc will be called also for css files and images and javscript, not just .aspx I understand that there could be multiple requests to the server (although I am not using javascript, css or images in my example). What throws me is the multiple calls to Session_Start(), coming from a Java background, I would've expected only one call. Regards ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] Newbie Question: Web app life cycle events
On Mon, 27 Oct 2008 13:21:18 +0200 Roger [EMAIL PROTECTED] wrote: On Monday 27 October 2008 12:12:21 Joe Audette wrote: One possible cause to keep in mind is if Mono is handling all requests for the app them begin request etc will be called also for css files and images and javscript, not just .aspx I understand that there could be multiple requests to the server (although I am not using javascript, css or images in my example). What throws me is the multiple calls to Session_Start(), coming from a Java background, I would've expected only one call. Browsers also request favicon.ico, which will also be handled by xsp. regards, marek ___ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list