[Mono-list] Newbie Question: Web app life cycle events

Joe Audette joe_audette at yahoo.com
Mon Oct 27 06:12:21 EDT 2008


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 <roger.varley at googlemail.com> 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>
>        <title>Default</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 at 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
joe.audette at gmail.com
http://www.sourcetreesolutions.com
http://www.mojoportal.com


More information about the Mono-list mailing list